Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalrain

PHP search of database not generating any results...

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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]

:(

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

×

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.