Searching two fields simultaneously
-
http://htmlweb.ru/ajax/example/search.php I did everything exactly as on the website. How do you make a name search? I've done something like this, but for now, I'm only looking for OR by name, and I'm just looking for a name and a name at the same time.
<? include('auth/bd.php'); $searchq = $_GET['name']; $getName = mysql_query('SELECT * FROM users WHERE firstname LIKE "%'.addslashes($searchq).'%" OR lastname LIKE "%'.addslashes($searchq).'%"'); if(!empty($searchq)) while ($row = mysql_fetch_array($getName)) echo $row['firstname']." ".$row['lastname'] . '<br/>'; ?>
-
The code or the exact sql will work at the next set.
Let's say $searchq = (All Pupkin or Pupkin Vasia)
And the columns in the table are as follows:
firstname = (xxxvxx) , lastname = (xxxxPupkinxxxxxxx)
or
firstname = (xxxPupkinxxx) , lastname = (xxxxxxxxxxx)
include('auth/bd.php'); $searchq = $_GET['name']; $searchq = addslashes($searchq); $sql = "SELECT * FROM `users` WHERE ( `firstname` LIKE CONCAT('%',SUBSTRING_INDEX('".$searchq."', ' ', 1),'%') AND `lastname` LIKE CONCAT('%',SUBSTRING_INDEX('".$searchq."', ' ', - 1),'%') ) OR ( `firstname` LIKE CONCAT('%',SUBSTRING_INDEX('".$searchq."', ' ', - 1),'%') AND `lastname` LIKE CONCAT('%',SUBSTRING_INDEX('".$searchq."', ' ', 1),'%') )"; $getName = mysql_query($sql); if(!empty($searchq)) while ($row = mysql_fetch_array($getName)) echo $row['firstname']." ".$row['lastname'] . '<br/>';
And by the way, not using mysql_connect,mysql_query...
Use it. http://php.net/manual/ru/book.pdo.php
I hope so. Good luck.