Jump to content

while loop mysql


MetalSmith

Recommended Posts

Anyone know why I get this from my mysql query?It adds an extra key for some reason.

 

$types = array();

while ($row =  mysql_fetch_array($query_name,MYSQL_NUM))

{

    $types[] = $row;

}

print_r ($types);

 

 

Array (

[0] => Array ( [0] => Matt )

[1] => Array ( [0] => Larissa )

[2] => Array ( [0] => Braden )

[3] => Array ( [0] => Tom ) )

 

 

Link to comment
https://forums.phpfreaks.com/topic/229733-while-loop-mysql/
Share on other sites

I don't understand your question?

 

It is NOT adding an extra key, all keys have a value.  Try wrapping the print_r() function in <pre> tags.

 

echo '<pre>'; print_r($types); echo '</pre>';

 

You will find you have a multi-dim. array, just like you ask PHP to build for you.

 

If you don't want it multi-dim.  then,

$types = array();
while ($row =  mysql_fetch_array($query_name,MYSQL_NUM))
{
    $types[] = $row[0];
}
echo '<pre>'; print_r($types); echo '</pre>';

Link to comment
https://forums.phpfreaks.com/topic/229733-while-loop-mysql/#findComment-1183436
Share on other sites

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.