philip ngu philip ngu - 6 months ago 12
SQL Question

Why i only get 1 row of ans?

while($row = mysql_fetch_array($result))
{
if (isset($row["name"]) && ($row["name"] != "")){
$contentStr = $row["name"];
}
break;
}
mysql_close($con);


This works but not the way i want.
I want to show all the data that i get from.
Example in got 4 data now on database and using \n for the next line to show another data. How to write the format ?

Answer

Firstly, remove the break. It is serving no purpose.

Now, I believe what you want to do is obtain all the row["name"] values into one String, namely $contentStr, separated by a newline.

If this is the case, use the following:

$contentStr .= $row["name"] . "\n"

Also, make sure to create an empty $contentStr before the loop.