elmas156 Posted February 11, 2012 Share Posted February 11, 2012 Hey everyone, I'm getting an error on this code and I'm having a difficult time sorting it out. Most of this page is in html, but here is what little PHP I'm using as of now: <select class="ddbox2" name="occasion"> <option value="select" selected>- Select -</option> <?php $resdate = "02/20/2012"; $result = mysql_query("SELECT `time` FROM delivery_times WHERE `index` > '0'"); while ($row = mysql_fetch_row($result)) { $posstime = $row[0]; $reserved = mysql_query("SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` == '$posstime'"); $rowcheck = mysql_num_rows($reserved); // <-- THIS IS LINE 198 if ($rowcheck == 0) { echo "<option value='$posstime'>$posstime</option>"; } } ?> </select> What I'm doing is creating a dropdown menu for an html form depending on what is in my database, but here is the error that I'm getting: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\new_site\custform.php on line 198" When I change line 198 to read: $rowcheck = mysql_num_rows($result); I don't get the error, but I don't get the information that I need to complete my task. I was thinking that maybe this query isn't allowed in a while loop for some reason, but I don't think that would be the case. Any ideas on what I could be doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/256915-baffled-on-this-one/ Share on other sites More sharing options...
elmas156 Posted February 11, 2012 Author Share Posted February 11, 2012 Finally found the problem! $reserved = mysql_query("SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` == '$posstime'"); SHOULD BE... $reserved = mysql_query("SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` = '$posstime'"); TOO MANY "=" BETWEEN "`deltime`" and "'$posstime'" Thanks to anyone who tried to help! Quote Link to comment https://forums.phpfreaks.com/topic/256915-baffled-on-this-one/#findComment-1317109 Share on other sites More sharing options...
AyKay47 Posted February 11, 2012 Share Posted February 11, 2012 what data types are `resdate` and `deltime` set to in the database? you are using a comparison operator in your query, change to: $sql = "SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` = '$posstime'"; $reserved = mysql_query($sql) or die("Query: " . $sql . "<br />" . mysql_error()); EDIT: I see that you found the solution, however this should really be done with a join for optimization Quote Link to comment https://forums.phpfreaks.com/topic/256915-baffled-on-this-one/#findComment-1317110 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.