Jump to content

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

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.