Two numbers ib Between Not working Properly in PDO

This is my code actually it will work in SQL but not in code…

 $ss="25000";
 $sss="1000000";
 $query1 = "SELECT * FROM `tbl_user_reg` WHERE `income` BETWEEN :ss AND :sss";
 $query2 = $conn->prepare($query1);
 
 $query2->bindParam(':ss', $ss);
 $query2->bindParam(':sss', $sss);
 
 $query2->execute();

but if
$ss=“100000”;
$sss=“2000000”;

it will working Properly…,

i think it will took only first digit of both the number…?

any suggestion please

where are the numbers? $ss and $sss are strings.
this is like trying to calculate johnphpnewb minus 10.

an income implies money, which is a number or integer.

$ss = 25000; $sss = 1000000;

I don’t know what “doesn’t work in code” means.

Yes it is working in sql while Writing on XAMPP but in code it is not working …

Actually if
$ss = 25000;
$sss = 1000000;

query will calculate $ss is greater than $sss in PDO

are you setting the income column data type as decimal/numeric or char/varchar?

I need to see an example of this. I know that ORM’s will do this as I’ve had a bug like this before, but this is an actual query and isn’t likely. You are telling it exactly where to do the comparison.

it is a searching criteria…,

So i want to get records whose income between 25000 to 1000000 so i tries in sql query on xampp

  SELECT * FROM `tbl_user_reg` WHERE `income` BETWEEN 25000 AND 1000000

It is working …,

but in php code

   $ss=  (int)$_SESSION['income1']; //value 25000
   $sss= (int)$_SESSION['income11'];  // value 1000000
   $query1 = 'select * from tbl_user_reg where  income BETWEEN :income1 AND  :income2  ';
   $query2 = $conn->prepare($query1);
   $query2->bindParam(':income1', $ss);
   $query2->bindParam(':income2', $sss);
   $query2->execute();
    if($query2->rowCount())
    echo "Yes";
      else
    echo "No";

This is my query but Here query is not working… it will show No message…,
if i changes number as
$ss= (int)$_SESSION[‘income1’]; //value 100000
$sss= (int)$_SESSION[‘income11’]; // value 1000000
It will work…,

any suggestion please…?

It is working for me now…!

i just added in bindParam(’:income1’, $ss, PDO::PARAM_INT)

thank you for your response…

rowCount() does not work on select statements. It is for Insert, Update, and Deletes.

Sponsor our Newsletter | Privacy Policy | Terms of Service