做一个相当常规的查询时,我突然发现了以下错误: Warning</b>: mysql_num_rows(): supplied argument is not a valid MySQL result resource
PHP MySQL的问题
这里是我的代码:
$query = "SELECT * FROM ImageGalleryPhotos ORDER BY ImageOrder";
$result = mysql_query($query);
/* create one master array of the records */
$imagesArray = array();
// here is the line where I'm getting the error I listed up top:
if(mysql_num_rows($result)) {
while($image = mysql_fetch_assoc($result)) {
$imagesArray[] = array('image'=>$image);
}
}
echo json_encode($imagesArray);
// And here I'm getting error # 2 (see below):
mysql_free_result($result);
?>
错误#2:<b>Warning</b>: mysql_free_result(): supplied argument is not a valid MySQL result resource
奇怪事情是,当我做没有“ORDER BY”业务的搜索时,一切正常,就像这样:
$query = "SELECT * FROM ImageGalleryPhotos";
如果在运行查询后输出mysql_error(),它会告诉你到底是什么问题。你假设你的查询已经工作,并且根本不做任何错误检查。 – andrewsi
为什么在'mysql_query()'行的末尾没有'或者死掉(mysql_error())',所以你会看到错误信息? – Barmar
听起来像你的'ORDER BY'有错误。你真的确定你的表中有一个ImageOrder列吗? – Travesty3