unemployment Posted October 28, 2010 Share Posted October 28, 2010 I can only search by first name in my search engine code. How can I search by both first and last name. Code is below: <?php include ('header.php'); //get data $button = $_GET['search']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword."; else { if (strlen($search)<1) echo "Search term too short."; else { echo "You searched for $search<hr>"; require ('connect.php'); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //contruct query $x++; if ($x==1) $construct .= "firstname LIKE '%$search_each%'"; else $construct .= " OR firstname LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM users WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if($foundnum==0) echo "No results found!<p>"; else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $firstname = $runrows['firstname']; $lastname = $runrows['lastname']; $url = $runrows['username']; echo " $firstname $lastname <a href='http://network.jasonbiondo.com/$url'>http://network.jasonbiondo.com/$url</a> "; } } } } include ('footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/217057-search-by-last-name/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.