search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thinkDoug
Forum Newbie
Posts: 2
Joined: Mon Dec 19, 2011 5:24 pm

search

Post 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
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: search

Post 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.
thinkDoug
Forum Newbie
Posts: 2
Joined: Mon Dec 19, 2011 5:24 pm

Re: search

Post by thinkDoug »

That works, thanks!
Post Reply