srhino Posted February 5, 2010 Share Posted February 5, 2010 Hi, I am trying to use a search box on my website to find a tournament name and a last name or first name when entered into the search form. I have the seasrch working when you put in the event name but I can not figure out how to pull up by lastname. here is my code $search = $_GET['searchFor']; $query = "SELECT tourname, lastname from events where tourname like '%$search%' or lastname like '%search%'"; $result = mysql_query($query) or die('Could not query database at this time'); echo "<h1>Search Results</h1><br><br>\n"; if (mysql_num_rows($result) == 0) { echo "<h2>Sorry, no events were found with '$search' in them.</h2>"; } else { echo "<h2>Events matching '$search':</h2><br><br>"; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $tournid = $row['tournid']; $tourname = $row['tourname']; $lastname = $row['lastname']; echo "<a href=\"index.php?content=showevent&id=$tournid\">$tourname</a><br>\n"; } } Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/191086-can-someone-please-help-with-a-search-statement/ Share on other sites More sharing options...
fizix Posted February 5, 2010 Share Posted February 5, 2010 Your query should look like this: $query = "SELECT tourname, lastname from events where tourname like '%$search%' or lastname like '%$search%' Note where I added the $ to or lastname like '%$search%'. Quote Link to comment https://forums.phpfreaks.com/topic/191086-can-someone-please-help-with-a-search-statement/#findComment-1007576 Share on other sites More sharing options...
srhino Posted February 5, 2010 Author Share Posted February 5, 2010 OHHHHHHHH Jeez sorry to waste time and space. I can't believe I did that! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/191086-can-someone-please-help-with-a-search-statement/#findComment-1007577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.