CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   Trying to display a div if date is today or greater (http://www.codingforums.com/showthread.php?t=282165)

Jodzzz 11-14-2012 02:23 PM

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 } ?>


AndrewGSW 11-14-2012 03:05 PM

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.

Jodzzz 11-14-2012 03:58 PM

1 Attachment(s)
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!

AndrewGSW 11-14-2012 04:46 PM

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 ;)

Jodzzz 11-15-2012 09:28 AM

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 11-22-2012 12:10 PM

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'])) {
                               
                                ?>



All times are GMT +1. The time now is 12:34 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.