Canman2005 Posted April 12, 2007 Share Posted April 12, 2007 [email protected] ?? [email protected] ?? 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 Link to comment https://forums.phpfreaks.com/topic/46738-return-rows-on-date-range/ 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. Link to comment https://forums.phpfreaks.com/topic/46738-return-rows-on-date-range/#findComment-227773 Share on other sites More sharing options...
Canman2005 Posted April 15, 2007 Author Share Posted April 15, 2007 cool, thanks Link to comment https://forums.phpfreaks.com/topic/46738-return-rows-on-date-range/#findComment-229687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.