How to query equals or greater than with pdo

Hello,
each row has a value
4
8
16
32
64
128
A numeric value received via POST
1 or 2 or 3 or 4 > I want it to find 4 from database
5 or 6 or 7 or 8 > I want it to find 8 from database
9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 > I want it to find 16 from database
… it will go on like this

What kind of query is needed, can you help?

This should work -

$sql = "SELECT data FROM your_table WHERE input = (SELECT input FROM your_table WHERE ? <= input ORDER BY input LIMIT 1)";
$stmt = $pdo->prepare($sql);
$stmt->execute([ $_POST['the_input_value'] ]);
$result_data = $stmt->fetchAll(PDO::FETCH_COLUMN);

echo '<pre>'; print_r($result_data);

The input column is the 2, 8, 16,… values. The data column are the β€œ8”,β€œ12” (for an 8 input) and β€œ12”,β€œ16”,β€œ8-8” (for a 16 input) that you previously showed for this task.

Thanks for your reply
I couldn’t understand this
Maybe I didn’t explain the topic well.
I have two columns in the table
1st column, input column
2nd column, data column

1st column
4
8
16
32
64
or it could be as follows
4
8
12
16
20
24
28
32
as
Equal or first greater than input_value

I tried the code but didn’t get the result I wanted

I moved this switch system to the database in order to be able to edit when necessary in the administration panel.
However, I can’t query like this switch system

switch($kamera_sayisi){ 
case $kamera_sayisi <= 4 : $hedefsecenek= array(
"4", "8"); break;
case $kamera_sayisi <= 8 : $hedefsecenek= array(
"8", "16", "4-4"); break;
case $kamera_sayisi <= 12 : $hedefsecenek= array(
"16", "8-4", "4-4-4"); break;
case $kamera_sayisi <= 16 : $hedefsecenek= array(
"16", "32", "8-8", "4-4-4-4"); break;
case $kamera_sayisi <= 20 : $hedefsecenek= array(
"32", "16-4", "8-8-4", "8-8-8", "4-4-4-4-4"); break;
case $kamera_sayisi <= 24 : $hedefsecenek= array(
"32", "16-8", "8-8-8", "4-4-4-4-4-4"); break;
case $kamera_sayisi <= 28 : $hedefsecenek= array(
"32", "16-16", "8-8-8-4"); break;
case $kamera_sayisi <= 32 : $hedefsecenek= array(
"32", "16-16", "8-8-8-8", "4-4-4-4-4-4-4-4"); break;
}

What result did you get?

What is the data type of the input column? It must be an integer for the <= comparison to work correctly.

What is the high level overview of what you have going on? What problem is this code trying to solve?

These are combinations of satellite receiver distribution amplifiers. If the needed number of outputs ($kamera_sayisi) is greater than a level, but less then or equal to the next level, the code uses the combinations at the matching level. For example, if the needed number of outputs is 5, which is greater then 4 but less then or equal to 8, the array of combinations β€œ8”, β€œ16”, β€œ4-4”, is used, meaning that a single 8 output, a single 16 output, or two 4 output amplifiers will satisfy the project requirements.

1 Like

Sample
When I give 3 values, it gives 32 results.
When I value 1 to 4, it should give the result 4
When I value 5 to 8, it should give the result 8

Yes it is just like that :grinning: :+1: :+1:

Sponsor our Newsletter | Privacy Policy | Terms of Service