在loop...please帮助中找不到错误
foreach($cat1 as $category){
$query="SELECT parent FROM categories where id=".$category;
$result = mysql_query($query);
$line = mysql_fetch_assoc($result);
array_push($cat1,$line['parent']);
}
发布于 2012-10-16 12:32:05
该错误是由于空结果集或查询中的错误造成的。
请使用以下步骤进行调试:
echo $query
优先(检查所有参数是there)Write mysql_query($query)
还是die(mysql_error());
这将显示mysql错误(如果有)。
发布于 2012-10-16 12:30:24
在获取之前,您应该检查$result
以确保您使用的是资源。另外,检查您是否真的有一个来自mysql_num_rows
的rows查询。
foreach($cat1 as $category){
$query="SELECT parent FROM categories where id=".$category;
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
if(mysql_num_rows($result) > 0) {
$line = mysql_fetch_assoc($result);
array_push($cat1,$line['parent']);
}
else {
// do something else
}
}
发布于 2012-10-16 12:38:11
我还会尝试通过运行以下命令来调试查询:
SELECT parent FROM categories where id=3
或在id=
后插入有效的值ID
另外,要选择的字段是:parent
是INT还是VARCHAR?(我的猜测是,根据您提供的错误,它是一个字符串)
https://stackoverflow.com/questions/12914550
复制相似问题