Jump to content


Photo

PHP search of database not generating any results...


  • Please log in to reply
3 replies to this topic

#1 digitalrain

digitalrain
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 May 2006 - 02:20 PM

Hi folks...newbie here.

I have a database created whose purpose is to list showtimes of a tv show for
the 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 name
and 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:

<?
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 while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}

?>

It generates the output page complete with the table with headings, but no results
appear in that table.

Help!

Thanks,

Cynthia



#2 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 31 May 2006 - 03:10 PM

use this code

SELECT * 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
"Syntax error" .. WHERE THE **** IS IT?!

#3 digitalrain

digitalrain
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 May 2006 - 03:17 PM

[!--quoteo(post=378735:date=May 31 2006, 11:10 AM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ May 31 2006, 11:10 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
use this code

SELECT * 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:

$srch="%".$search."%";
$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";

and

$srch=$search;
$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";

:(


#4 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 31 May 2006 - 03:19 PM

[!--quoteo(post=378739:date=May 31 2006, 10:17 AM:name=ChickieGamer)--][div class=\'quotetop\']QUOTE(ChickieGamer @ May 31 2006, 10:17 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi...

I tried it two ways, neither of which worked:

$srch="%".$search."%";
$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";

and

$srch=$search;
$query = "SELECT * FROM helpline WHERE MATCH(country, state) AGAINST ('$srch')";

:(
[/quote]

hmm..works for me!


"Syntax error" .. WHERE THE **** IS IT?!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users