Canman2005 Posted April 12, 2007 Share Posted April 12, 2007 russell@2fl.co.uk ?? russell@twofl.co.uk ?? Hi all I have a sql table which holds events for my website, in each row there is the following fields id (auto increase) title (text) date_from (dates are stored as YYYY-MM-DD) date_end (dates are stored as YYYY-MM-DD) I then have a query which looks in that table and returns all rows that have todays date inside the "date_from" field, the query looks like <?php $meventssql = "SELECT * FROM events WHERE datefrom = '".date('Y-m-d')."'"; $meventsquery = @mysql_query($meventssql,$connection) or die(mysql_error()); while ($meventsrow = mysql_fetch_array($meventsquery)) { ?> <?php print $meventsrow['title']; ?><br> <?php } ?> How can I re-write the query, so that it uses the date_from & date_end and returns all rows which fall in between those dates, so a row with a date_from set to "2007-01-01" and the date_end set to "2007-01-03", it would then return that row on 2007-01-01 2007-01-02 2007-01-03 Does that make sense? Been having a hunt around, but cant seem to find anything which would do this. Can anyone help me? Thanks in advance Ed Quote Link to comment Share on other sites More sharing options...
s0c0 Posted April 12, 2007 Share Posted April 12, 2007 trying using between. I can't remember the exact syntax since I am still learning mysql, but google the use of mysql between. It would look something like this: SELECT * FROM events WHERE BETWEEN datefrom = date(value) and date(value); Hope that helps. Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted April 15, 2007 Author Share Posted April 15, 2007 cool, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.