[thelist] How to store data in multidimensional array in a loop(PHP)

Raoul Snyman raoul.snyman at saturnlaboratories.co.za
Wed Sep 19 07:55:36 CDT 2007


Hi Stefan

On Wed, 19 Sep 2007 08:24:57 +0200, Stefan Schwarzer
<st.schwarzer at geois.de> wrote:
> I need to store three pieces of data - a result of a SQL query - in a
> multidimensional array, but don't really succeed. Sometimes it works,
> but then the output doesn't work accordingly.

This following snippet of code will run a query, and then return the
results in an array:

$rResult = mysql_query($sSql, $this->rConnection);
if (!empty($rResult)) {
  $aResults = array();
  while ($aRow = mysql_fetch_array($rResult)) {
    $aResults[] = $aRow;
  }
  return $aResults;
}


This is PHP 4, though I think it should be ok in 5.

-- 
Raoul Snyman
Saturn Laboratories
e: raoul.snyman at saturnlaboratories.co.za
w: http://www.saturnlaboratories.co.za/
b: http://blog.saturnlaboratories.co.za/
   http://raoulsnyman.co.za/




More information about the thelist mailing list