php - LIKE function SQL -


i've been using function like in statement not doing expected do, user on site has subject looks hello welcome #room hows going #fun , im using like function select users subject containing #fun statement looks this;

$search = 'fun'; $sql = "select * `usr_users` `subject` '%$search%'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) {     echo $row['username']; } 

however when query runs selects users have fun @ begining of subject or not @ all. there different function can use select words within in subject not first word.

you need % @ beginning of string search.

$sql = "select * `usr_users` `subject` '%$search%'"; 

--- update ---

it may failing because may need escape data. check errors mysql_error() against query. might throwing it. mysql_real_escape_string(). # culprit if it's part of actual query. or use htmlspecialchars() or echo out query.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -