Forum Moderators: coopster

Message Too Old, No Replies

MySql help needed

         

dwighty

10:08 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Hi guys,

I have written a basic script that shows the latest gigs for a band, what i am after is that once the date has been and gone, the gig details change colour so users can see the old and the new straight of.

Below is what i have so far...

// Create a Query
$query ="SELECT DATE_FORMAT(Date, '%d.%m.%Y at %H:%i'), Subject, Venue FROM DB_Table_Name ORDER BY Date DESC";

// Execute the Query
$result = mysql_query($query) or die ("Error in Query: $query. ".mysql_error());

// See if any rows were returned
if (mysql_num_rows($result) > 0) {

// If the statement is YES then Print them 1 after another
while(list($Date, $Subject, $Venue) = mysql_fetch_row($result)) {

echo "<b>$Date:<br />What?</b>&nbsp;&nbsp;$Subject<br />";
echo "<b>Where?</b> &nbsp;&nbsp;$Venue<br />";
echo "<hr />";

Any help would be appreciated.

Thanks

coopster

2:35 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You will need to compare the date pulled from the database with the current date to determine whether or not the date is in the past. If so, modify your markup to show the different color.

dreamcatcher

4:12 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you aren`t already doing so you might want to use a DATE field in your database which stores the date in the format YYYY-MM-DD. This is the easiest one for filtering date information.

Then you can do as coopster has already mentioned.

dc

dwighty

8:47 am on Nov 15, 2005 (gmt 0)

10+ Year Member



Thanks guys,

Yeah I am using the DATE function. Where do I start with working out if the date is in the past?

I have not been able to find any previous threads on this, or do you guys know of a tutorial link I can use.

Thanks for your Help

Dwighty

jezzer300

11:08 am on Nov 15, 2005 (gmt 0)

10+ Year Member



This will get you started, it's not tested, just off the top of my head. (You could convert the date to an integer in PHP if you don't want to use SQL.)

// Create a Query
$query ="SELECT DATE_FORMAT(Date, '%d.%m.%Y at %H:%i'),(Date<now()) AS Old_Gig, Subject, Venue FROM DB_Table_Name ORDER BY Date DESC";

// Execute the Query
$result = mysql_query($query) or die ("Error in Query: $query. ".mysql_error());

// See if any rows were returned
if (mysql_num_rows($result) > 0) {

// If the statement is YES then Print them 1 after another
while(list($Date, $Old_Gig, $Subject, $Venue) = mysql_fetch_row($result)) {

if ($Old_Gig == 1) echo '<span style="color:gray">';
echo "<b>$Date:<br />What?</b>&nbsp;&nbsp;$Subject<br />";
echo "<b>Where?</b> &nbsp;&nbsp;$Venue<br />";
if ($Old_Gig == 1) echo '</span>';

echo "<hr />";

[edited by: jezzer300 at 11:09 am (utc) on Nov. 15, 2005]

jackvull

11:09 am on Nov 15, 2005 (gmt 0)

10+ Year Member



use getdate() to find the current date and compare it to that

dwighty

1:42 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Thanks a lot guys, I will work on this a bit later.

Thanks

dwighty

8:55 am on Nov 17, 2005 (gmt 0)

10+ Year Member



jezzer300,

Thanks for your help on this. Makes sense to me now and it works a treat.

Nice one.