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
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.

Link to comment
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");

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.