1

I just made a quick little script with SQL query. Now when I go to phpmyadmin and execute

SELECT name FROM players WHERE online='1' ORDER BY name ASC

It outputs the desired players ( 0TheMonk, Player, Veeve )

But with PHP:

$query=mysql_query("SELECT name FROM players WHERE online='1' ORDER BY name ASC");
$query_array=mysql_fetch_array($query);
echo implode(',',$query_array);

It echoes: 0TheMonk,0TheMonk

Instead of: 0TheMonk,Player,Veeve

It always outputs the first player in the array, twice. What am I doing wrong? Thanks in advance.

2

2 Answers 2

2

Use while loop

$query=mysql_query("SELECT name FROM players WHERE online='1' ORDER BY name ASC");
while($query_array=mysql_fetch_array($query))
{
    echo $query_array['name'].",";
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, it actually helped, but now I have every player twice. 0TheMonk,0TheMonkPlayer,PlayerVeeve,Veeve That's even more weird O.o
Thank you so so so so much! <3
0

Try this : Almost same as Sumits answer.

$res    = array();
$query=mysql_query("SELECT name FROM players WHERE online='1' ORDER BY name ASC");
while($query_array=mysql_fetch_array($query))
{
    $res[]   = $query_array['name'];
}

echo implode(",",$res);

In this case there will not a extra , at the ens

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.