digitalrain Posted May 31, 2006 Share Posted May 31, 2006 Hi folks...newbie here.I have a database created whose purpose is to list showtimes of a tv show forthe country or state that is entered into the search form.My form is simple -- a text field where the user enters their country or state nameand then clicks submit.The database is called mydb and the table is called helpline.A php file called srch.php processes the whole thing. Here is my code for srch.php:[code]<?if ($search) // perform search only if a string was entered.{#defines database access and connects to database$user = "root";#$pass = "";$database = "mydb";mysql_connect(localhost,$user,$pass);@mysql_select_db($database) or die( "Unable to select database");$srch="%".$search."%";$query = "select * from helpline WHERE Country LIKE '$srch' || State LIKE '$srch'";$result = mysql_db_query("mydb", $query);if ($result){echo "Here are the program times for your area:<br><br>";echo "<table width=90% align=center border=1><tr><td align=center bgcolor=#00FFFF>Country</td><td align=center bgcolor=#00FFFF>State</td><td align=center bgcolor=#00FFFF>City</td><td align=center bgcolor=#00FFFF>Network</td><td align=center bgcolor=#00FFFF>Station</td><td align=center bgcolor=#00FFFF>Channel</td><td align=center bgcolor=#00FFFF>Time</td></tr>";while ($r = mysql_fetch_array($result)) { // Begin while$country = $r["Country"];$state = $r["State"];$city = $r["City"];$network = $r["Network"];$station = $r["Station"];$channel = $r["Channel"];$time = $r["Time"];echo "<tr><td>$country</td><td>$state</td><td>$city</td><td>$network</td><td>$station</td><td>$channel</td><td>$time</td></tr>";} // end whileecho "</table>";} else { echo "problems...."; }} else {echo "Search string is empty. <br> Go back and type a string to search";}?>[/code]It generates the output page complete with the table with headings, but no resultsappear in that table.Help!Thanks,Cynthia Quote Link to comment https://forums.phpfreaks.com/topic/10861-php-search-of-database-not-generating-any-results/ Share on other sites More sharing options...
legohead6 Posted May 31, 2006 Share Posted May 31, 2006 use this codeSELECT * FROM helpline WHERE MATCH(title, description) AGAINST ('$srch')change title and discription to the 2 fileds you would like searched in your database! sldo take away the percent symbols in your varibale for $srch Quote Link to comment https://forums.phpfreaks.com/topic/10861-php-search-of-database-not-generating-any-results/#findComment-40588 Share on other sites More sharing options...
digitalrain Posted May 31, 2006 Author Share Posted May 31, 2006 [!--quoteo(post=378735:date=May 31 2006, 11:10 AM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ May 31 2006, 11:10 AM) [snapback]378735[/snapback][/div][div class=\'quotemain\'][!--quotec--]use this codeSELECT * FROM helpline WHERE MATCH(title, description) AGAINST ('$srch')change title and discription to the 2 fileds you would like searched in your database! sldo take away the percent symbols in your varibale for $srch[/quote]Hi...I tried it two ways, neither of which worked:[code]$srch="%".$search."%";$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";[/code]and[code]$srch=$search;$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";[/code]:( Quote Link to comment https://forums.phpfreaks.com/topic/10861-php-search-of-database-not-generating-any-results/#findComment-40592 Share on other sites More sharing options...
legohead6 Posted May 31, 2006 Share Posted May 31, 2006 [!--quoteo(post=378739:date=May 31 2006, 10:17 AM:name=ChickieGamer)--][div class=\'quotetop\']QUOTE(ChickieGamer @ May 31 2006, 10:17 AM) [snapback]378739[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi...I tried it two ways, neither of which worked:[code]$srch="%".$search."%";$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";[/code]and[code]$srch=$search;$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";[/code]:([/quote]hmm..works for me! Quote Link to comment https://forums.phpfreaks.com/topic/10861-php-search-of-database-not-generating-any-results/#findComment-40593 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.