这工作:
$customerBox = mysql_query("MY SQL STATEMENT HERE");
$boxRow = mysql_fetch_array($customerBox);
$customerBox = mysql_query("MY SQL STATEMENT AGAIN");
while($item = mysql_fetch_assoc($customerBox)) {
foreach ($item as $columnName => $value) {
if (empty($value)) {
print $columnName;
}
}
}这不是:
$customerBox = mysql_query("MY SQL STATEMENT HERE");
$boxRow = mysql_fetch_array($customerBox);
while($item = mysql_fetch_assoc($customerBox)) {
foreach ($item as $columnName => $value) {
if (empty($value)) {
print $columnName;
}
}
}为什么?我想我还不明白变量是如何工作的。
发布于 2010-12-24 04:26:26
问题在于,由于查询返回一行,所以没有什么可获取的了。
mysql_fetch_*函数获取当前行,然后将行指针提前到下一行。如果当前行不存在,则返回false。因此,在第二次调用mysql_fetch_assoc时,指针位于第二行,但该行不存在,因此不会执行循环。你有两个选择:
好:删除while循环,并将foreach改为使用$boxRow:
foreach ($boxRow as $columnName => $value) {
//...
}Ok:使用mysql_data_seek倒带MySQL的行指针
$boxRow = mysql_fetch_array($customerBox);
mysql_data_seek($customerBox, 0);
while(...){发布于 2010-12-24 04:24:24
这可能与mysql_fetch_array()有关,而不是变量。试着把这个:
mysql_data_seek ( $customerBox , 0 );就在while循环开始之前。我很想看到结果。
发布于 2010-12-24 04:50:09
$customerBox =mysql_query(“我在这里的SQL语句”);
$boxRow = mysql_fetch_array($customerBox);
时间($item = mysql_fetch_field($customerBox)) { foreach ($item as $columnName => $value) { if (空($value)){ print $columnName;}}
https://stackoverflow.com/questions/4524150
复制相似问题