Jump to content

Show future event dates


p2492

Recommended Posts

I am trying to only show the events occurring today and on future dates. The problem is that the day, month, and year in my database are separate and with the code I have now it isn't treating them as one, so the month will show future months, the day will show future days, and the year will show future years. For example, today is 01.17.2011 and the next day (that should be displayed as well) is 02.03.2011, but with the code I have it only shows 01.17.2011 because the day in the other date is less than 17. I hope I am making sense.. any help would be great

 

<?php
    // connect to the RDBMS
    $db = mysql_connect("$site","$user","$pass") 
        or die_now("Could not connect to database server. Check passwords and sockets");

    // select the database
    mysql_select_db("$database",$db) 
        or die_now("Could not select database $database. Check database name.");

    // select all the shows in the database
    $result = mysql_query("select show_id, month, day, year, location, venue
        from $database_table
	where month >= month( now())
	and day >= day(now())
	and year >= year(now())
	order by year, month, day limit 5",$db) 
        or die_now("Could not select shows");

    // output the current shows
echo("<div class='shows_place'>\n");        
    while($row = mysql_fetch_array($result)) {
        $the_id = $row["show_id"];
        $the_month = $row["month"];
        $the_day = $row["day"];
        $the_year = $row["year"];
        $the_location = $row["location"];
        $the_venue = $row["venue"];

        // shows
        echo("<table><tr><td>" . "$the_month" . "." . "$the_day" . "." . "$the_year" . " - </td>");
        echo("<td>" . "$the_venue" . " - </td>");
        echo("<td>" . "$the_location" . "</td>");
    }
    echo("</tr></table></div>");
?>

Link to comment
Share on other sites

Any particular reason you split the date up? If you combined them in YYYY-MM-DD format this query would be really easy.

 

But otherwise,

year > this year OR
year = this year AND month > this month OR
year = this year AND month = this month AND day >= this day

Link to comment
Share on other sites

Any particular reason you split the date up? If you combined them in YYYY-MM-DD format this query would be really easy.

 

But otherwise,

year > this year OR
year = this year AND month > this month OR
year = this year AND month = this month AND day >= this day

 

The script was already set up this way, I am just editing it. I don't know much about PHP and databases if you couldn't tell. That didn't seem to work, it didn't show anything. Thanks for your time!

Link to comment
Share on other sites

Any particular reason you split the date up? If you combined them in YYYY-MM-DD format this query would be really easy.

 

I changed the date to YYYY-MM-DD. How do I go about showing only current and future dates now? Thanks

Link to comment
Share on other sites

SELECT `field1`, field2` FROM `table` WHERE `date_field` > CURDATE()

 

Hmm that doesn't seem to be working either, it's still showing the past dates.

'date' is the name of the date field. This is what I have..

 

    $result = mysql_query("select show_id, month, day, year, location, venue, DATE_FORMAT(`date`,'%m.%d.%y') AS date
        from $database_table
	WHERE 'date' > CURDATE()
	ORDER BY date ASC limit 5",$db) 
        or die_now("Could not select shows");

Link to comment
Share on other sites

WHERE 'date' > CURDATE()

 

^^^ That's testing if the string 'date' (not your date column) is greater than the curdate(). Remove the single-quotes from that. Also, by using date as the alias name for the date_format() term, your WHERE and ORDER BY terms will use the formatted value. Pick a different alias name for the date_format() term.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.