Jump to content

BETWEEN sql query


benji87

Recommended Posts

Can someone please correct me where im going wrong here please?

 

This is my code for trying to pull results that have a event date between two dates:

 

<?
include "db.php";

$act_type = 'All';
$area = 'Portsmouth';
$start = '01/01/2008';
$end = '30/05/2008';

$query = mysql_query("SELECT * FROM events WHERE date BETWEEN '$start' AND '$end'");
while ($data = mysql_fetch_array($query))
{
?>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td width="33%" bgcolor="#efefef"><?=$data["event"]?></td>
    <td width="47%" bgcolor="#efefef"><?=$data["date"]?></td>
  </tr>
</table>
<?
}
?>

 

For some reason it returns all records in the table rather than just the ones between the two dates.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/86438-between-sql-query/
Share on other sites

some database treate the BETWEEN ....AND.. differently.

 

Some database will do what your asking for and others will do the opposite. I.E. display all records that are not between those dates.

 

Check your result echoed back and see if the opposite of what you want is happening

Link to comment
https://forums.phpfreaks.com/topic/86438-between-sql-query/#findComment-441719
Share on other sites

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.