注意:数组到字符串的转换 - PHP &我的SQL
我一直在阅读这里与此相关的每个线程,但我总是弄错.
I've been reading in every thread in here that is related to this but I always get it wrong.
请帮忙,因为我总是收到错误
Please help cause I always get the error
注意:数组到字符串的转换"在$address[] =mysql_result($row, 0);"
"Notice: Array to string conversion" in line "$address[] = mysql_result($row, 0 );"
在下面.请帮忙.
if ($p_address=mysql_query($email))
{
$address = array();
while($row = mysql_fetch_assoc($p_address))
{
$address[] = mysql_result($row, 0 );
}
$all_address = implode(',', $address);
推荐答案
更改此行
$address[] = mysql_result($row, 0 );
为此:
$address[] = $row;
然后要查看新的 $address
数组中可用的键和值,您可以执行以下操作:
And then to see the keys and values available in the new $address
array, you can do something like this:
print_r($address);
为了保持 implode()
的功能,请执行以下操作:
In order to keep implode()
functional, do something like this:
for ($i = 0; $i < count($address); $i++) {
$all_address[] = implode(',', $address[$i]);
}
最终输出:
if ($p_address=mysql_query($email))
{
$address = array();
while($row = mysql_fetch_assoc($p_address))
{
$address[] = $row;
}
for ($i = 0; $i < count($address); $i++) {
$all_address[] = implode(',', $address[$i]);
}
// Example for outputting on screen:
foreach ($all_address as $aa) {
print $aa . "<br/>
";
}
}
希望有帮助...
相关文章