Jump to content

PHP search of database not generating any results...


digitalrain

Recommended Posts

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:

[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 while
echo "</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 results
appear in that table.

Help!

Thanks,

Cynthia

Link to comment
Share on other sites

[!--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 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:

[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]

:(
Link to comment
Share on other sites

[!--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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.