Jump to content

multidimensional array help


solarisuser

Recommended Posts

Hello All,

 

I can't get this to work right,  $aResults should be ~200 records

(mysql query is correct)...

 

$aResults = array();
$get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200");
$row = mysql_fetch_array($get);
$num = mysql_num_rows($get);

for ($i=0;$i<count($num);$i++)
{
$aResults[$i]['id'] = $row['id'];
$aResults[$i]['value'] = $row['value'];
$aResults[$i]['info'] = $row['info'];
}

var_dump($aResults);

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/57788-multidimensional-array-help/
Share on other sites

$aResults = array();
$get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200");
while ($row = mysql_fetch_array($get)) {
        $aResults[] = $row;
}

var_dump($aResults);

 

You have to iterate through the query to get all the records.

$aResults = array();

$get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200");

$num = mysql_num_rows($get);

 

for ($i=0;$i<count($num);$i++)

{

$row = mysql_fetch_array($get);

$aResults[$i]['id'] = $row['id'];

$aResults[$i]['value'] = $row['value'];

$aResults[$i]['info'] = $row['info'];

}

var_dump($aResults);

 

thats the code you have the prob is that you put the $row = mysql_fetch_array($get); outside the loop any way it will work now but its better to use the while  loop its shorter

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.