Jump to content

[SOLVED] Slimming down results with SQL query


r00ttap

Recommended Posts

My problem is that I'm trying to make my code as efficient as possible by pulling only what I need from the database. I will try and draw this out so it will make some sense to you.

 

My current database would be:

+--------------+--------------+
|  end_time    |     date
+--------------+--------------+
|  15:30:00    | 2009-02-02
+--------------+--------------+

I need something posted UNTIL the end_time is up on that specific date. My query looks somethign like this:

 

 

$campus_name = mysql_query("SELECT * FROM table WHERE campus = 'campus_name' AND date >= 
CURDATE() ORDER by date, time") or die(mysql_error());

 

Of course this will keep something posted until the date changes but I really need the text to disappear after the time is over. Is this something the SQL can't handle and that I may just have to narrow it down even more with PHP?

 

I figured it out.

 

$campus_name = mysql_query("SELECT * FROM table WHERE campus = 'campus_name' AND CONCAT(date,' ',time) >= NOW() ORDER by date, time") or die(mysql_error());

 

Which simply concatenates the date and time to YYYY-MM-DD HH:MM:SS which is exactly what NOW() returns.

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.