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


Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.