php - How to get data from a table with a foreach loop -


i trying data table array, , want use foreach loop not while speed issues.

i tried using

function getrowsassoc() {     $ret = array();     while (($temp = mysql_fetch_assoc($this->result)) !== false)     {         if (count($temp) > 0)         {             $ret[] = $temp;         }     }     if (count($ret) > 0)     {         return $ret;     }     else     {         return false;     } } 

however results in to.

array (     [0] => array ( [mysku] => bb1-3500-48 [upc] => 721343100171 )      [1] => array ( [mysku] => bc7-3501-19 [upc] => 721343103516 )     [2] => array ( [mysku] => bc7-3501-95 [upc] => 721343103523 )      [3] => array ( [mysku] => bb1-3502-12 [upc] => 721343114000 )     [4] => array ( [mysku] => bc7-2370-03 [upc] => 721343121602 ) ) 

the problem instead of returning assoc array adding numbered array in top of cannot data item codes.

i like this

array (          [mysku] => bb1-3500-48 [upc] => 721343100171           [mysku] => bc7-3501-19 [upc] => 721343103516          [mysku] => bc7-3501-95 [upc] => 721343103523           [mysku] => bb1-3502-12 [upc] => 721343114000          [mysku] => bc7-2370-03 [upc] => 721343121602      ) 

specify key:

function getrowsassoc() {     $ret = array();     while (($temp = mysql_fetch_assoc($this->result)) !== false)     {         if (count($temp) > 0)         {             $ret[$temp["mysku"]] = $temp;         }     }     if (count($ret) > 0)     {         return $ret;     }     else     {         return false;     } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -