Two numbers ib Between Not working Properly in PDO

#1

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

#2

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;
#3

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

#4

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

#5

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

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

#6

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

#7

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.

#8

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…?

#9

It is working for me now…!

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

thank you for your response…

#10

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