phpmysqldatetimetimestampepg

Get value between to hours from mysql using php


I'm trying to get a specific show description from my DB but I really don't know how, I know i'm new into this, the table (guide) have 2 DATETIME values "start" and "end"

If I use this:

$sql = mysql_query("SELECT * FROM guide WHERE start  >= CURDATE()");

Only return the first value from the table, and inclusive its the wrong value, please I need some help to get this, because I don't find a solution from other on this web


Solution

  • You should be able to use mysql's between function to pull the records in the current time range.

    select * from guide where now() between start and end
    

    To limit the returns you can add in additional parameters, this may give you back no results though so have a default value.

    select * from guide where channel = $channel_ID and now() between start and end
    

    You also should look into parameterized queries and updating your driver. Having variables in your query isn't the best practice.