Jump to content

query question


corillo181

Recommended Posts

why isn't this working?

i know i would make it work if i just putting with out array but i want to do it with array

[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'])
echo $arran;
?>[/code]
Link to comment
Share on other sites

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