$query = mysql_query("SELECT * FROM fruit WHERE color='red' ");
while ($row = mysql_fetch_array($query)) {
echo $row['name']."|" ;// this echo apple|strawberry|cherry
}
如何使一个php变量等于mysql_fetch_array的结果?我需要将其等同于
$newname="apple|strawberry|cherry"
,以便可以将新变量$newname
用于另一个进程。谢谢。 最佳答案
连接而不是回显:
$newname = '';
while ($row = mysql_fetch_array($query)) {
$newname .= $row['name']."|" ;// this echo apple|strawberry|cherry
}
$newname = rtrim($newname,'|');