Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2012, 02:23 PM   PM User | #1
Jodzzz
New Coder

 
Join Date: Nov 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
Jodzzz is an unknown quantity at this point
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 } ?>
Jodzzz is offline   Reply With Quote
Old 11-14-2012, 03:05 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"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

Last edited by AndrewGSW; 11-14-2012 at 03:11 PM..
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 03:58 PM   PM User | #3
Jodzzz
New Coder

 
Join Date: Nov 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
Jodzzz is an unknown quantity at this point
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
Click image for larger version

Name:	Untitled-3.jpg
Views:	20
Size:	49.9 KB
ID:	11704  
Jodzzz is offline   Reply With Quote
Old 11-14-2012, 04:46 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
__________________
"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

Last edited by AndrewGSW; 11-14-2012 at 04:50 PM..
AndrewGSW is offline   Reply With Quote
Old 11-15-2012, 09:28 AM   PM User | #5
Jodzzz
New Coder

 
Join Date: Nov 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
Jodzzz is an unknown quantity at this point
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
Jodzzz is offline   Reply With Quote
Old 11-22-2012, 12:10 PM   PM User | #6
Jodzzz
New Coder

 
Join Date: Nov 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
Jodzzz is an unknown quantity at this point
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'])) { 
				
				?>
Jodzzz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:47 AM.


Advertisement
Log in to turn off these ads.