PDA

View Full Version : sql problem


scoutt
Sun 14th Oct '01, 9:19pm
I have this search form and it searches mysql for the search term.
its a basic search if you will. if I enter a search word it works fine,
but if it finds more then that one search word it list it but it gives
the wrong catagory for the search term. so one it right and one
is wrong. Aslo if i search for something tha tI know is not there, it
doesn't say no matches.

like this


category title by
1 something me
1 another title me

now that is the outcome of the search. the first one is correct and
the second one's title has the search term in it but it comes back
with the wrong category, suppose to be lets say #2 category.

that make since?
this is my form with the sql statement.

<form action="search.php" method="post">
<tr>
<td width="100%" align="center" colspan="4"><font size="2">
<input name="searchword" size="20" style="FONT-SIZE: 8pt" size="1">
<input type="submit" value="Search" name="submit" style="FONT-SIZE: 8pt" size="1">
in category

<select style="FONT-SIZE: 8pt" size="1" name="catid">
<option value="0" selected>Search All</option-->
<?

$sql_select = "select * from $cat_tbl where catfatherid = 0 order by catname";
$result = mysql_query ($sql_select);

while ($row = mysql_fetch_array($result)) {

$catid1 = $row["catid"];
$catfatherid = $row["catfatherid"];
$catname = $row["catname"];
$catdescription = $row["catdescription"];
print("<option value=\"$catid1\">");
print("$catname");

print("</option>");
};

?>
</select>
<br><br>&nbsp; and show
<select style="FONT-SIZE: 8pt" size="1" name="limit">
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
</select> results on page.</font></td>
</tr>

</form>


<?
if ($submit)
{

// Header table for all categories (just above all links)


print("<tr>");
print("<td><b>$category</b></font></td>");
print("<td><b>$title</b></font></td>");
print("<td><b>$custom_field_1_text</b></font></td>");
print("<td><b>$date_added</b></font></td>");
print("</tr>");

// End of Header table

if (!$order)
{
$order = sitedate;
}

if (!$limit)
{
$limit = 30;
}
if ($catid == '0')
{
$catid = '%%';
}
$sql_links = "select * from $cat_tbl, $ads_tbl where
catfatherid='$catid' AND (sitetitle like '%$searchword%' or
catname like '%$searchword%' or sitedescription like
'%$searchword%') limit $limit";
print("$sql_links");

$sql_result = mysql_query ($sql_links);
$num_links = mysql_num_rows($sql_result);

for ($i=0; $i<$num_links; $i++)
{
$row = mysql_fetch_array($sql_result);
$siteid = $row["siteid"];
$sitetitle = $row["sitetitle"];
$sitedescription = $row["sitedescription"];
$siteurl = $row["siteurl"];
$sitedate = $row["sitedate"];
$sitehits = $row["sitehits"];
$sitevotes = $row["sitevotes"];
$name = $row["name"];
$email = $row["email"];
$sitevotes = $row["sitevotes"];
$catname = $row["catname"];
$custom_field_1 = $row["custom_field_1"];
$custom_field_2 = $row["custom_field_2"];
$custom_field_3 = $row["custom_field_3"];
$custom_field_4 = $row["custom_field_4"];
$custom_field_5 = $row["custom_field_5"];
$custom_field_6 = $row["custom_field_6"];
$custom_field_7 = $row["custom_field_7"];
$custom_field_8 = $row["custom_field_8"];
$dates= "$sitedate";
$sitedate1 =date("d.m.Y",time($dates));

// Here we print out each link.
if ($num_links ==0)
{
print("<tr><td>No hits</td></tr>");
print("</table>");
exit;
}else{

some other code..