How to compare data in range number without using explode

86
September 26, 2018, at 09:40 AM

I've table target

id | target_percent
1  | 1-50
2  | 50-100
3  | 150-200

Can I use data target_percent to compare number example :

$a = 55;

I want to find what target id where $a in .

now I loop data and use explode to do something like this .

       foreach ($target as $item) {
            $percent = explode("-", $item->target_percent);
            $startpercent = (int)$percent[0];
            $endpercent = (int)$percent[1];
            if ($startpercent <= $percentSell && $percentSell <= $endpercent) {
               return $item->id
            } 
        }

this way everything work but It too complicated.

I just want to know is their some way to make it easier?

Answer 1

It possible to change table columns to id, target_percent_from, target_percent_to?

If it is, You can use Laravel DB and write something like this:

\DB::table('target')
    ->where('target_percent_from', '>', $a)
    ->where('target_percent_to',   '<', $a)
    ->get();
READ ALSO
How can I store a returned google app script &ldquo;doPost(e)&rdquo; function in a variable in cURL?

How can I store a returned google app script “doPost(e)” function in a variable in cURL?

I have written a doPost(e) function on google app script that will return a number depending on the data that is sent throughThe script returns a number, somewhat like this:

96
Global variable not working inside a basic IF statement

Global variable not working inside a basic IF statement

I am trying to make a submit action insert data into the database with

82
Use conditions in MySql select queries

Use conditions in MySql select queries

I want to get the same column in my database depending on the different values in other columnsIn my table I have multiple records for same NIC

104