0
votes

It's friday, so I am obviously not seeing things strait so I thought to ask here.

I want to get a list of names from the database using:

$test = mysql_query("SELECT Names FROM Content ORDER BY Names");

This should give JimMikePeter (at least it does in PHP MyAdmin)

This is not very readable so I thought, lets implode:

$line = implode( ", ", $test);
echo $line;

This should give: Jim, Mike, Peter but it doesn't, it gives: Warning: implode() [function.implode]: Invalid arguments passed

Also I want the result like this: "Jim", "Mike", "Peter" (with quotes)

Any thoughts?

2
implode() accepts an array as it's 2nd parameter, you're currently passing the return value from mysql_query which isn't an array. - Clive
mysql_query returns a resource, not a string. According to php.net "The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data. " - j08691

2 Answers

1
votes

You have to fetch the array using mysql_fetch_array. Using a query as a parameter in implode() will give you an error

0
votes

You should know that mysql_query returns a resource documented in the PHP manual you nead to fetch the data with a fetch function like mysql_fetch_array