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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Trying to display a div if date is today or greater

    Hi Guys,

    I'm a novice at this and i'm bloody stuck!

    Basically i want to display a div if theres a record in a table from either todays date or in the future.

    Here comes my very bad code.....

    Code:
    <?php
    			// Retrieve Weekly Special Rate
    			$week_special_rate = exc_db_query("SELECT week_special_rate FROM calendar_weeks");
    			$week_special_rate_array = exc_db_fetch_array($week_special_rate);
    			?>
    
    			<?php
    			// Show Last Minute Deals button only if there are any deals to display at a date greater than current day
    			if ($week_special_rate > '0') { ?>
    				<article class="homefocusbox lastminbox">
    					<div class="focus_box_overlay">
    						<h3>Last Minute</h3>
    						<p>For details of our<br />current last minute<br />deals</p>
    						<p><a href="last-minute.php">Click here...</a></p>
    					</div>
    				</article>
    			<?php } ?>

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Where is the date that you wish to compare? I assume you need to extract it from a field of your table.

    I'm assuming, also, that it should be exec_db_query etc. Actually, this is probably your own function, so ignore this line.
    Last edited by AndrewGSW; 11-14-2012 at 03:11 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Basically theres a bunch of dates in a row, if there is data in another row next to it which has a date of Today or Now or greater i want that div to display.

    i've attached a screenshot which might explain better.


    Thanks mate!
    Attached Thumbnails Attached Thumbnails Trying to display a div if date is today or greater-untitled-3.jpg  

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    It's slightly confusing as your code refers to 'week_special_rate' but the field in your table is named 'special_offer'..

    Anyway, I believe you need a query like:

    SELECT special_offer FROM yourtable WHERE `date` > NOW()
    or
    SELECT special_offer FROM yourtable WHERE `date` > NOW() and special_offer > 0

    It might be more complicated if your 'date' field is a string.

    BTW (Personally) I wouldn't use 'date' as a field-name - it can only lead to trouble or confusion later
    Last edited by AndrewGSW; 11-14-2012 at 04:50 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    lol i give you the screenshot of a different table, i think this should be an if statement. basically i need to know how to write this in php.

    if in a row column "week_special_rate" contains any data other than 0 and "start_date" column is today or in the future then display div

  • #6
    New Coder
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I managed to get it to work in the end with this code:

    Code:
    	 <?php
    			 
    				// Get todays date
    				$today = date("Y-m-d");
    
    				// Retrieve Weekly Special Rate
    				$week_special_rate_query = exc_db_query("SELECT week_special_rate FROM calendar_weeks WHERE week_special_rate > '0' AND start_date >= '" . $today . "'");
    				$week_special_rate_array = exc_db_fetch_array($week_special_rate_query);
    				
    				// Show Last Minute Deals button only if there are any deals to display
    				if (exc_not_null($week_special_rate_array['week_special_rate'])) { 
    				
    				?>


  •  

    Posting Permissions

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