Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to a where statement 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a select query that gets put together by use checkbox selection. That works okay, however I am now trying to add between two dates in the query.

//$from_date = "2006-01-01";
//$to_date = "2006-09-24";

//$where=$where AND date_added BETWEEN '".$from_date."' AND ".$to_date."'";

I cannot seem to get the correct syntax for the above to work. Tried many permutaions but cannot get there. Anyone know how to do it. Many thanks
 
Your SQL looks fine, but the PHP looks funny. Should it be:
[tt]
$where=$where." AND date_added BETWEEN '".$from_date."' AND '".$to_date."'";
[/tt]
I don't know if PHP uses Perl-style string interpolation, but if it does, you could use the neater:
[tt]
$where.=" AND date_added BETWEEN '$from_date' AND '$to_date'";
[/tt]
 
Hello Sleipnir, its PHP. I put it on this site as more I though MySql, but could be wrong. Its knowing where things split. Thanks
 
Thankyou very much Tony, it worked perfectly.
 
First, if you post program code to a programming-language forum, your fellow members can make reasonable assumptions about what language the code is in, so it's not necessary to explicitly say so. However, when you post program code in a forum not dedicated to a general programming language, it is unreasonable to expect everyone to know what you've posted. A simple "I have this PHP code..." somewhere in your post would have been sufficient.


Second, the code you posted was badly-formed. If you had tried to run it, the interpreter would have mentioned mentioned at least one error, and you should have posted that error. If you haven't tried to run it, then you're trying to get others to write your code for you.




Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top