Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Date field greater than or equal to today

    Hello

    I've been trying to solve this problem by reading a forum post at http://www.phpfreaks.com/forums/inde...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 Code:
    <?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 ) {
    $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");
    ?>

  • #2
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    You are missing a parenthesis in "DATE(NOW()" part.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Add proper error checks to your code, like
    PHP Code:
    $result mysql_query($query) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    nickburrett (11-22-2011)

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts
    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
    Code:
    $query = "SELECT * FROM bookings WHERE start_time >= DATE(NOW() ORDER BY start_time ASC";

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by nickburrett View Post
    Now getting another error
    You need to add a parenthesis:

    DATE(NOW())

  • Users who have thanked Placido for this post:

    nickburrett (11-22-2011)

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    But WHY are you using DATE(NOW()) in the first place?

    Why not just use CURDATE() ????

    Code:
    $query = "SELECT * FROM bookings WHERE start_time >= CURDATE() ORDER BY start_time ASC";
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    nickburrett (11-22-2011)

  • #7
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Thank you Old Pedant

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

    Nick

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Trivial.

    Code:
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    nickburrett (11-22-2011)

  • #9
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Perfect, thanks once again!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •