Jump to content

php mysql where statment partial match numbers only


vanderlay

Recommended Posts

Hi All,
Firstly I can't even think how to word the title for this question correctly so I hope some of you can help explain the answer to this problem.

I am doing a straight foward

$a = SELECT * FROM table WHERE id = $idnum
$b = MYSQL_NUM_ROWS($a)

$idnum comes from var passed in url from prev page.

the above statment returns a +ve result under the following,
ie $idnum = 100 & id 100 exists is in db

search for 100
$b = 1 (expected)

search for 100abcd
$b = 1 (unexpected)

search for abcd100
$b = 0 (expected)

so the basic Q is why does the MYSQL_NUM_ROWS rtn a +ve match for a search with letters &/or numbers added to the end of a seach string?

FYI i noted it only happens with numbers as the first part of the string not letters?

Thx
Art


A string starting with numbers will be converted into a real (float) matching those numbers.  A string starting with letters will be converted into the real 0.  Then the comparison proceeds as usual.

See http://dev.mysql.com/doc/refman/4.1/en/type-conversion.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.