How can I create 1 variable that has the contents of an entire field in a MySQL table?

Question by Baltie: How can I create 1 variable that has the contents of an entire field in a MySQL table?
I have the following code

$result = mysql_query ($query) or die(mysql_error());

if ($result)
{
while ($row = mysql_fetch_assoc ($result))
{
echo “{$row[“fruit”]}, “;
}
}

What this produces is
apples, oranges, bananas

What I want to have is
$fruit_types = “apples, oranges, bananas”;

How can I accomplish this?

Please help!

Best answer:

Answer by Kenneth
Instead of putting ‘echo “{$row[“fruit”]}, “;’ in the body of the loop, put $fruit_types in there and just concatenate $row[“fruit”] to it. After the loop ends, the echo it out.

Add your own answer in the comments!

Leave a Reply

%d bloggers like this: