rs_nayr Posted March 20, 2009 Share Posted March 20, 2009 good day to all guyz,, i have this sql between statement to display available vehicles on a particular date/day,, and it works when i used this code $sql_v="SELECT r_vehicle FROM reservation WHERE pick_date between '2009-02-01' and '2009-02-03'"; $result_v=mysql_query($sql_v) or die (mysql_error()); $num=mysql_num_rows($result_v); echo"number of results = $num"; this code returns number of results = 2 which means that theres a record between '2009-02-01' and '2009-02-03' but when is used variables to replace those numbers on my sql statement the number of results returns 0 heres the code $pd="2009-02-01"; $rd="2009-02-03"; $sql_v="SELECT r_vehicle FROM reservation WHERE pick_date between $pd and $rd"; $result_v=mysql_query($sql_v) or die (mysql_error()); $num=mysql_num_rows($result_v); echo"number of results = $num"; have some ideas and info guys to make this work? thanks in advance Link to comment https://forums.phpfreaks.com/topic/150277-solved-variable-on-sql-between-statement/ Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 Try with single quotes it literal. $pd='2009-02-01'; $rd='2009-02-03'; i think lol <?php $pd='2009-02-01'; $rd='2009-02-03'; $sql_v="SELECT r_vehicle FROM reservation WHERE pick_date between '".$pd."' and '".$rd."' "; $result_v=mysql_query($sql_v) or die (mysql_error()); $num=mysql_num_rows($result_v); echo"number of results = $num"; ?> you forgot the single quotes on the select '$hi' Link to comment https://forums.phpfreaks.com/topic/150277-solved-variable-on-sql-between-statement/#findComment-789180 Share on other sites More sharing options...
rs_nayr Posted March 20, 2009 Author Share Posted March 20, 2009 yeah, it works!!! thanks redarrow,, cu again,, Link to comment https://forums.phpfreaks.com/topic/150277-solved-variable-on-sql-between-statement/#findComment-789184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.