Jump to content

[SOLVED] variable on sql between statement


rs_nayr

Recommended Posts

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

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'

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.