开发者

Quering integer in MySQL over PHP

I'm working with a table ("Item") which has the field "Aprovado" and it's an integer that checks if the item is approved or not (1 for yes, 0 for no) (not my table, I would have chosen proper boolean).

I know there are items there, and I know there are lots of items with "Aprovado" set to 1. (I am successful with queries "SELECT * FROM Item ORDER BY ItemID ASC")

yet, when I do:

mysql_select_db($theDatabase, $db) or die("Could not find database."); 
$query = "SELECT * FROM Item WHERE Aprovado = 1";
$resultID = mysql_query($query开发者_运维问答, $db) or die("Data not found."); 

It just returns "Data not Found." What's wrong?


Could try changing your die(...) into:

die('Invalid query: ' . mysql_error());

That will show you the actual MySQL error.


mysql_query does not return FALSE if the query returns no data. It only returns false on an error condition:

$result = mysql_query($query, $db) or die(mysql_error());
if (mysql_num_rows($result) == 0) {
   die("Data not found");
}
$row = mysql_fetch_assoc($result);
$resultID = $row['resultID'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜