...

View Full Version : Date field greater than or equal to today



nickburrett
11-21-2011, 02:55 PM
Hello

I've been trying to solve this problem by reading a forum post at http://www.phpfreaks.com/forums/index.php?topic=234552.0 but I seem to come across an error not mentioned:


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/discos/public_html/booking/index.php on line 12

Can anyone tell me what I'm doing wrong?


<?php
include("header.php");
?>
<?php
include("connect.php");
$query = "SELECT *
FROM bookings
WHERE start_time >= DATE(NOW()
ORDER BY start_time ASC";

$result = mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close(); ?>
<table class="pretty" width="100%" align="center">
<?
if ($num > 0 ) {
$i=0;
while ($i < $num) {
$start_time = mysql_result($result,$i,"start_time");
$finish_time = mysql_result($result,$i,"finish_time");
$client_title = mysql_result($result,$i,"client_title");
$client_first = mysql_result($result,$i,"client_first");
$client_last = mysql_result($result,$i,"client_last");
$partner_title = mysql_result($result,$i,"partner_title");
$partner_first = mysql_result($result,$i,"partner_first");
$partner_last = mysql_result($result,$i,"partner_last");
$married_last = mysql_result($result,$i,"married_last");
$client_email = mysql_result($result,$i,"client_email");
$client_street1 = mysql_result($result,$i,"client_street1");
$client_street2 = mysql_result($result,$i,"client_street2");
$client_town = mysql_result($result,$i,"client_town");
$client_county = mysql_result($result,$i,"client_county");
$client_postcode = mysql_result($result,$i,"client_postcode");
$client_daytime = mysql_result($result,$i,"client_daytime");
$client_evening = mysql_result($result,$i,"client_evening");
$event_occasion = mysql_result($result,$i,"event_occasion");
$event_occasion_name = mysql_result($result,$i,"event_occasion_name");
$venue_name = mysql_result($result,$i,"venue_name");
$venue_street1 = mysql_result($result,$i,"venue_street1");
$venue_street2 = mysql_result($result,$i,"venue_street2");
$venue_town = mysql_result($result,$i,"venue_town");
$venue_county = mysql_result($result,$i,"venue_county");
$venue_postcode = mysql_result($result,$i,"venue_postcode");
$client_notes = mysql_result($result,$i,"client_notes");
$total_fee = mysql_result($result,$i,"total_fee");
$deposit_due = mysql_result($result,$i,"deposit_due");
$deposit_date = mysql_result($result,$i,"deposit_date");
$deposit_amount = mysql_result($result,$i,"deposit_amount");
$deposit_method = mysql_result($result,$i,"deposit_method");
$balance_due = mysql_result($result,$i,"balance_due");
$balance_date = mysql_result($result,$i,"balance_date");
$balance_amount = mysql_result($result,$i,"balance_amount");
$balance_method = mysql_result($result,$i,"balance_method");
$admin_notes = mysql_result($result,$i,"admin_notes");
$meeting_time = mysql_result($result,$i,"meeting_time");
$meeting_street1 = mysql_result($result,$i,"meeting_street1");
$meeting_street2 = mysql_result($result,$i,"meeting_street2");
$meeting_town = mysql_result($result,$i,"meeting_town");
$meeting_county = mysql_result($result,$i,"meeting_county");
$meeting_postcode = mysql_result($result,$i,"meeting_postcode");
$facebook_contact = mysql_result($result,$i,"facebook_contact");
$marketing_emails = mysql_result($result,$i,"marketing_emails");
$new_enquiry = mysql_result($result,$i,"new_enquiry");
$waiting_for_client = mysql_result($result,$i,"waiting_for_client");
$waiting_for_nick = mysql_result($result,$i,"waiting_for_nick");
$booking_unpaid = mysql_result($result,$i,"booking_unpaid");
$booking_paid = mysql_result($result,$i,"booking_paid");
$booking_completed = mysql_result($result,$i,"booking_completed");
$booking_cancelled = mysql_result($result,$i,"booking_cancelled");
$client_went_elsewhere = mysql_result($result,$i,"client_went_elsewhere");
$id = mysql_result($result,$i,"id");
?>
<tr valign="top">
<td><div><?php echo date("D d M Y", strtotime($start_time)); ?><br>
<?php echo date("H:i", strtotime($start_time)); ?> - <?php echo date("H:i", strtotime($finish_time)); ?></div></td>
<td><div><?php echo "$venue_name"; ?></div>
<div><?php echo "$venue_street1"; ?></div>
<div><?php echo "$venue_street2"; ?></div>
<div><?php echo "$venue_town"; ?></div>
<div><?php echo "$venue_county"; ?></div>
<div><?php echo "$venue_postcode"; ?></div></td>
<td><div><?php echo "$client_title"; ?> <?php echo "$client_first"; ?> <?php echo "$client_last"; ?></div>
<div><a href="<?php echo "$client_email"; ?>"><?php echo "$client_email"; ?></a></div>
<div><?php echo "$client_daytime"; ?></div>
<div><?php echo "$client_evening"; ?></div></td>
<td valign="middle" align="center">
<p><a href="update.php?id=<?php echo "$id"; ?>">View / Edit</a></p>
<p><a href="echosign.php?id=<?php echo "$id"; ?>">Echosign Adults</a></p>
<p><a href="echosignkids.php?id=<?php echo "$id"; ?>">Echosign Kids</a></p>
</td>
<td valign="middle" align="center"><a href="delete.php?id=<?php echo "$id"; ?>">Delete</a></td>
</tr>
<?php ++$i; } }?>
</table>
<?php
include("footer.php");
?>

Placido
11-21-2011, 05:12 PM
You are missing a parenthesis in "DATE(NOW()" part.

abduraooft
11-21-2011, 05:33 PM
Add proper error checks to your code, like

$result = mysql_query($query) or die(mysql_error());

nickburrett
11-21-2011, 06:29 PM
Hello

Now getting another error:


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY start_time ASC' at line 1


$query = "SELECT * FROM bookings WHERE start_time >= DATE(NOW() ORDER BY start_time ASC";

Placido
11-21-2011, 08:15 PM
Now getting another error

You need to add a parenthesis:


DATE(NOW())

Old Pedant
11-21-2011, 08:39 PM
But WHY are you using DATE(NOW()) in the first place?

Why not just use CURDATE() ????



$query = "SELECT * FROM bookings WHERE start_time >= CURDATE() ORDER BY start_time ASC";

nickburrett
11-22-2011, 08:23 PM
Thank you Old Pedant

Just out of interest, is it possible to only return records that fall between Monday and Friday?

Nick

Old Pedant
11-22-2011, 09:31 PM
Trivial.



SELECT list, of, fields FROM table WHERE DAYOFWEEK( somedatetimefield ) IN (2,3,4,5,6)

weekdays are numbered 1 for Sunday through 7 for Saturday.

nickburrett
11-22-2011, 10:10 PM
Perfect, thanks once again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum