E
E
Evgeny Ivanov2017-10-26 09:30:07
PHP
Evgeny Ivanov, 2017-10-26 09:30:07

Why does the like operator work differently?

Mysql, PHP, Apache (web site)
I use the like operator in my SQL query.
PHP code is the same. The data is different. The result of the behavior of the like operator is different. Weird.
(The code is used in conjunction with ajax - a drop-down list, everything is standard.)
//keyword - title of the work (text). For example - "Building a big house"

$select_result=mysql_query("SELECT * FROM `my_table` WHERE `job_name` like '".$keyword."%' ORDER BY job_name");

As a result, everything works as it should.
I have entries in the table - Construction of a large house, Construction of a small house, Page of a large house.
Entering Str we see 3 all records, entering Stroh - 2 first records, entering Construction b - 1 record.
Works as it should.
//keyword - work value (in the form of a number). For example - "1.0.001" The field in the table is char(255) utf8_general_ci.
if (is_numeric($keyword)==true)
{
$select_result=mysql_query("SELECT * FROM `my_table` WHERE `job_value` like '".$keyword."%' ORDER BY job_value");
}

I have records in the table - 1.0.001, "1.1.001, 1.1.222, 1.1.333.
By entering 1 we see all the records. By entering 1. we see all the records. By entering 1.1 we see 3 records.
But by entering 1.1. we do not see any one record. But there are three of them!
Everything works with text, but not with numbers.
Why does the like operator work differently?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Hog, 2017-10-26
@logpol32

Condition does not work

is_numeric('1.') // true
is_numeric('1.1') // true
is_numeric('1.1.') // false

Therefore your request is not executed at all

K
kisaa, 2017-10-26
@kisaa

Numeric representation with multiple decimal points??? What standard describes this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question