gpt4 book ai didi

php - 如何使 php 变量等于 mysql_fetch_array 的结果?

转载 作者:行者123 更新时间:2023-12-01 00:15:21 25 4
gpt4 key购买 nike

$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,'|');

关于php - 如何使 php 变量等于 mysql_fetch_array 的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5094918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com