Jump to content

Baffled on this one...


elmas156

Recommended Posts

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.