Jump to content

[SOLVED] Slimming down results with SQL query


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!

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.