angst
09-09-2005, 04:01 PM
Hello,
I'm trying to search mysql with php,
and have one or two problems,
my code:
<?php
include 'admin/conn.php';
$link = mysql_connect($SqlHost, $SqlUser, $SqlPass) or die('Login details incorrect');
$db_selected = mysql_select_db($SqlDb, $link) or die('Database name incorrect');
$search = $_REQUEST['search'];
$searchdrop = $_REQUEST['searchdrop'];
//Count Search Results
Function SearchCount($search,$searchdrop)
{
global $SqlHost;
global $SqlUser;
global $SqlPass;
global $SqlDb;
$link = mysql_connect($SqlHost, $SqlUser, $SqlPass) or die('Login details incorrect');
$db_selected = mysql_select_db($SqlDb, $link) or die('Database name incorrect');
$query = "SELECT * FROM listings WHERE keywords LIKE \"%$search%\" AND status=2 AND cid=$searchdrop";
$numguests = mysql_query($query) or die("Select Failed!");
$numguest = mysql_fetch_array($numguests);
echo "$numguest[0]";
}
echo "search results for \"<b>$search</b>\" returned ";
SearchCount("$search","$searchdrop");
echo " matches<br /><br />";
$result = mysql_query("SELECT * FROM listings WHERE keywords LIKE \"%$search%\" AND status=2 AND cid=$searchdrop");
while ($row3 = mysql_fetch_assoc($result))
{
echo "<table cellpadding=2 cellspacing=1 border=0 width=400 bgcolor='#E6E6E6'>";
echo "<tr><td bgcolor='#FF9E21' align=left><a href='$row3[link]' target='_blank'>$row3[Name]</td></tr>";
echo "<tr><td align=left>$row3[Description]</td></tr>";
echo "</table><br />";
}
?>
first problem,
my function:
Function SearchCount($search,$searchdrop)
to count the number of records found, gives me 9 for some reason, and only one record is being displayed using the same select query as you can see, or maybe I'm just not seeing something.
also if I just click on the search button on my search form, it returns everything in the mysql table i'm searching, why does it do this?
thanks in advance for your time!
-Ken
I'm trying to search mysql with php,
and have one or two problems,
my code:
<?php
include 'admin/conn.php';
$link = mysql_connect($SqlHost, $SqlUser, $SqlPass) or die('Login details incorrect');
$db_selected = mysql_select_db($SqlDb, $link) or die('Database name incorrect');
$search = $_REQUEST['search'];
$searchdrop = $_REQUEST['searchdrop'];
//Count Search Results
Function SearchCount($search,$searchdrop)
{
global $SqlHost;
global $SqlUser;
global $SqlPass;
global $SqlDb;
$link = mysql_connect($SqlHost, $SqlUser, $SqlPass) or die('Login details incorrect');
$db_selected = mysql_select_db($SqlDb, $link) or die('Database name incorrect');
$query = "SELECT * FROM listings WHERE keywords LIKE \"%$search%\" AND status=2 AND cid=$searchdrop";
$numguests = mysql_query($query) or die("Select Failed!");
$numguest = mysql_fetch_array($numguests);
echo "$numguest[0]";
}
echo "search results for \"<b>$search</b>\" returned ";
SearchCount("$search","$searchdrop");
echo " matches<br /><br />";
$result = mysql_query("SELECT * FROM listings WHERE keywords LIKE \"%$search%\" AND status=2 AND cid=$searchdrop");
while ($row3 = mysql_fetch_assoc($result))
{
echo "<table cellpadding=2 cellspacing=1 border=0 width=400 bgcolor='#E6E6E6'>";
echo "<tr><td bgcolor='#FF9E21' align=left><a href='$row3[link]' target='_blank'>$row3[Name]</td></tr>";
echo "<tr><td align=left>$row3[Description]</td></tr>";
echo "</table><br />";
}
?>
first problem,
my function:
Function SearchCount($search,$searchdrop)
to count the number of records found, gives me 9 for some reason, and only one record is being displayed using the same select query as you can see, or maybe I'm just not seeing something.
also if I just click on the search button on my search form, it returns everything in the mysql table i'm searching, why does it do this?
thanks in advance for your time!
-Ken