Page 1 of 1

search

Posted: Mon Dec 19, 2011 5:31 pm
by thinkDoug
Basically, I am searching for specific ids that I have in my db. I am trying to display all of the ids that are in my search field regardless of any letters before or after the number.

so if I am searching for abc55cba I want my results to show record #55, #155, #255, #355, #455, #555...

Currently I can search 55abc and get the results that I want, but if I have any characters before the number, it will not bring back any results.

code:

$ids= $_POST['ids'];
SELECT id,description FROM class WHERE upper(details) LIKE upper('%$ids%') ORDER BY id DESC

Re: search

Posted: Tue Dec 20, 2011 1:56 pm
by tr0gd0rr
I think you want a regular expression. Consider this one that removes all but digits:

Code: Select all

$ids = preg_replace('/\D/', '', $_POST['ids']);
And don't forget to call `mysql_real_escape_string()` before putting variables into your SQL.

Re: search

Posted: Tue Dec 20, 2011 4:29 pm
by thinkDoug
That works, thanks!