Jump to content

query question


corillo181

Recommended Posts

when i use this code i get
[code]<?php
$mns=mysql_query("select name from tra_music_song")or die(mysql_error());
while($names=mysql_fetch_array($mns)){
$arran=array($names['name']);
print_r($arran);
}

?>[/code]
this result
[code]
Array ( [0] => El Champion ) Array ( [0] => Un Segundo ) Array ( [0] => Bonside )
[/code]

and i want this result
[code]Array ( [0] => El Champion, [1] => Un Segundo, [2] => Bonside )[/code]

like a normal array outcome.
Link to comment
https://forums.phpfreaks.com/topic/34068-query-question/#findComment-160188
Share on other sites

Create the array before the while loop and use array_push() to fill in the values.

[code]<?php
$mns=mysql_query("select name from tra_music_song")or die(mysql_error());
$arran = array();
while($names=mysql_fetch_array($mns)){
array_push($arran, $names['name']);
}
print_r($arran);

?>[/code]

I'm pretty sure that will work, but I haven't used it in a while and could be wrong.  I know that array_push is what you need.  If that doesn't work, check out php.net and look up array_push.
Link to comment
https://forums.phpfreaks.com/topic/34068-query-question/#findComment-160192
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.