PHP MYSQL LIKE

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
anser316
Forum Newbie
Posts: 4
Joined: Sat Apr 12, 2008 7:31 pm

PHP MYSQL LIKE

Post by anser316 »

The user types something in a textbox.
e.g. s3

Code: Select all

echo "<td><input type=text name=dname></td>";
$dname=$_POST(dname);
This is the end of MYSQL statement
AND dname LIKE '%$dname%'.

If i wanted to get 'sample3', s3 will not work, because the letters have to be together, 'sam' would work.
how can i get 'sample3' from typing in 's3'
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP MYSQL LIKE

Post by Christopher »

You could split up $dname at the first non-letter and then do AND (dname LIKE '$dstart%' OR dname LIKE '%$dend').
(#10850)
Post Reply