Using greater than or less than in a PDO query

Hello,

WHERE xxxxx.xxxxxx=? AND xxxxxx.xxxxxx=? AND xxxxxx.xxxxxx=? AND transmitter.analog >=?

I will search the database on demand with the following code
If the request is greater than 16, how do I search for less than 65?

if($request < 9){
$sql->execute([$xxxxx, '1', $xxxxx, $analog_number]); // greater than >=8
}elseif($request < 17){
$sql->execute([$xxxxx, '1', $xxxxx, $analog_number]); // greater than >=16
}else{
$sql->execute([$xxxxx, '1', $xxxxx, $analog_number]); // less than <=64
}

Thank You

Why are you doing that in PHP when MySQL is perfectly capable of doing that?

You’re right, but I’m not that expert, so I do it because it’s easier.
Maybe I’ll do it later when I learn some more

I also do other operations optionally in “if()”. not just sql query

Since that logic is executing the same query with the same input variables and is apparently not doing anything uniquely with the fetched data, nothing useful is being accomplished by doing this. Just query for all the transmitter.analog values and put the result into the different ranges when you fetch it. If that’s not what you are doing, you would need to provide the top level context/purpose of doing this, not just the piecemeal part of the problem you are trying to make work.

Since there is a feature change in some products, I need to make changes to my existing codes.

I couldn’t find how to set it up exactly, it’s a bit complicated

I think it will work for me with “MAX() AS max, MIN() AS min” in the query

I’m trying to do something, it’s like I’m getting the result as a draft
I’ll try to make it more tidy later.
How do I get the ID of the product when using “MAX() AS max, MIN() AS min” in the query?
OR
In the query “column_name>=65” in such a query, 0 zero value will be returned because the largest value in the database is 64.
How do I get the highest 64 value in this case?

Edit
I think I will solve the problem by putting all the data into an array with “fetchAll(PDO::FETCH_ASSOC)”

No matter what I did I couldn’t get results
i don’t know if it works with function but how do i call multiple conditional
Conditions:

  1. brand. sample(TEKNILINE)
  2. optic_input. sample(8IF+MDU+RF)
  3. analog_splitter. sample >= 15. if greater than 15 is not available. give the biggest
  4. dijital_splitter. sample >= 33. if greater than 33 is not available. give the biggest
    and I want to get the ID of the product
    Array
    (
        [0] => Array
            (
                [id] => 1
                [brand] => NEXT
                [analog_splitter] => 32
                [dijital_splitter] => 64
                [optic_input] => MDU+RF
            )

        [1] => Array
            (
                [id] => 2
                [brand] => TEKNOLINE
                [analog_splitter] => 16
                [dijital_splitter] => 64
                [optic_input] => 8IF+MDU+RF
            )
    		
        [2] => Array
            (
                [id] => 2
                [brand] => TEKNOLINE
                [analog_splitter] => 8
                [dijital_splitter] => 32
                [optic_input] => 8IF+MDU+RF
            )
    		
        [2] => Array
            (
                [id] => 2
                [brand] => TEKNIX
                [analog_splitter] => 32
                [dijital_splitter] => 64
                [optic_input] => 8IF+MDU+RF
            )
    )

I gave up because it’s more complicated with the array
If pdo is not equal or greater in the query. how do i get the biggest one?

I want to get key by checking with value in this function
But it returns 0,1,2 as key

function transmitter_analog($number, $array) {
    sort($array);
    foreach ($array as $a=>$b) {
        if ($b >= $number) return $a;
    }
    return end(key($array));
}
$array = array("1"=>"8", "2"=>"16", "3"=>"32", "4"=>"64");
echo transmitter_analog('65', $array);
Sponsor our Newsletter | Privacy Policy | Terms of Service