hmjb Posted June 1, 2006 Share Posted June 1, 2006 Hello, does anyone have any idea as to why this piece of code returns no record from the database (the record is definately in there):$query1 = "SELECT * FROM listings WHERE listing_id =1";$result1 = mysql_query($query1);$num1 = mysql_num_rows($result1);if ($num1 > 1) { // results found echo "$num1 results found.</p>\n"; // Fetch and print all the records. while ($row = mysql_fetch_array($result1, MYSQL_ASSOC)) { echo $row['listing_code']; }I have made the code work with a similar SQL query:"SELECT * FROM listings WHERE site = 1 "the only differences between the column site and listing_id are that listing_id is int and site smallint plus listing_id is auto increment.I have been using navicat as a graphical interface to mysql and both the sql statement runs fine in there and returns records.Any help would be appreciated. Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/10920-newbie-sql-issue/ Share on other sites More sharing options...
hvle Posted June 1, 2006 Share Posted June 1, 2006 change this lineif ($num1 > 1) { // results foundto if ($num1 >= 1) { // results foundbecause listing_id is an auto increment, you always get 1 record with your $query1.your old code:if ($num1 > 1) { // results foundonly print if there're 2 or more records.regards, Quote Link to comment https://forums.phpfreaks.com/topic/10920-newbie-sql-issue/#findComment-40798 Share on other sites More sharing options...
hmjb Posted June 1, 2006 Author Share Posted June 1, 2006 Oh GOD! Thank you so much, dumb mistake but I wasted a whole afternoon!!! Quote Link to comment https://forums.phpfreaks.com/topic/10920-newbie-sql-issue/#findComment-41014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.