Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find similar results from all rows in DB with MySQL query
    text
    copied!<p>I would like to make "Search you'r LOGIN" like in facebook :</p> <p>Eg. searching for "Stock Overflow" would return</p> <pre><code>Stack Overflow SharePoint Overflow Math Overflow Politic Overflow VFX Overflow </code></pre> <p>Eg. searching for "LO" would return:</p> <pre><code>pabLO picasso michelangeLO jackson polLOck </code></pre> <p>Eg. searching for username "user123" would return :</p> <pre><code> user123 user1234 and etc ... </code></pre> <p>My Database rows :</p> <pre><code>userid | username | useremail | user_fname | user_lname </code></pre> <p>I would like to make a search input that search the word in any of this rows like above examples,</p> <p>Here my php till now :</p> <pre><code>$string = $purifier-&gt;purify(@$_POST['string']); $query = "SELECT * FROM users WHERE user_fname = '".$string."' OR user_lname = '".$string."' OR username = '".$string."' OR useremail= '".$string."'"; mysql_query("SET NAMES 'utf8'"); $result2 = mysql_query($query); $num = mysql_num_rows($result2); if($num == 1) { //true }else{ //not found nothing } </code></pre> <p>this way is not working good , and its not return all the similar reuslts of the word that i put in search input. plus how i return it with foreach if there is more then 1 similar result ?</p> <p>Thanks allot.</p> <p><strong>Update :</strong></p> <p>Thanks all , my updated code to fix it :</p> <pre><code> $query = "SELECT * FROM users WHERE user_fname like '%".$string."%' OR user_lname like '%".$string."%' OR username like '%".$string."%' OR useremail like '%".$string."%'"; </code></pre> <p>and i am not using mysql , just for the examples i had more easy to do like this..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload