rook1e Posted November 11, 2008 Share Posted November 11, 2008 Hi, i have created a search engine for resulting businesses in ireland its just a basic one but im having problems with search results. I'd like to paste my search.php file below and maybe you can point me in the right direction. Before i paste the code i would like to explain how i would like my results to display. I have Product/Service as my first input, I have Town as my Second, And County as my third. Im looking for a way to refine my search. Its not working the way i wanted it. For Example if i did a search for a taxi company, and typed say (curragh cabs) It doesnt bring this to the top but like 4 or 5 down the search. Also it brings up lots of other taxi services but it also brings up anything with curragh in it too. you can do a search and see what im referring too on www.ublinx.ie do a 2 word search like (car sales) and u can see it brings everything up with cars and sales. Its kinda annoying to be honest. If anyone out there would take the time to help me with this id be so greatful. Search.php Below: <?PHP include('top.txt'); ?> <?php $startat=$_GET['startat']; $searchstring = $_GET['searchstring']; $region = $_GET['region']; $county = $_GET['county']; // The apostrophe is trimmed but this is not displayed to the user. $searchstringapostrimmed = str_replace("'", "", $searchstring); $cur=0; $recordnumberer=$startat; $totalrecords = 0; include('opendb.php'); if(strcmp($county,"All")==0){ $countquery="SELECT COUNT(*) FROM businesses WHERE (MATCH (businessname, keywords) AGAINST('$searchstringapostrimmed')) AND (address1 LIKE '%{$region}%' or address2 LIKE '%{$region}%' or address3 LIKE '%{$region}%' or address4 LIKE '%{$region}%');"; $sql = "select * from businesses WHERE (MATCH (businessname, keywords) AGAINST('$searchstringapostrimmed')) AND (address1 LIKE '%{$region}%' or address2 LIKE '%{$region}%' or address3 LIKE '%{$region}%' or address4 LIKE '%{$region}%') ORDER BY classification desc LIMIT $startat, 10;"; $resultsmessage= "Search Results For \"$searchstring\" in \"$region\". "; } else { $countquery="SELECT COUNT(*) FROM businesses WHERE ((MATCH (businessname, keywords) AGAINST('$searchstringapostrimmed')) AND (address1 LIKE '%{$region}%' or address2 LIKE '%{$region}%' or address3 LIKE '%{$region}%') AND (address4='$county'));"; $sql = "select * from businesses WHERE ((MATCH (businessname, keywords) AGAINST('$searchstringapostrimmed')) AND (address1 LIKE '%{$region}%' or address2 LIKE '%{$region}%' or address3 LIKE '%{$region}%') AND (address4='$county')) ORDER BY classification desc LIMIT $startat, 10;"; $resultsmessage= "Search Results For \"$searchstring\" in \"$region\" in County \"$county\". "; } $resultsmessage = stripslashes($resultsmessage); $result=mysql_query($countquery,$db) or die (mysql_error()); $totalrecords=mysql_result($result,$cur,"count(*)"); $num=mysql_num_rows($result); echo("<center><table cellpadding=5 cellspacing=0 width=700 background=\"images/background.jpg\"><tr><td><Font class=\"bodyFont\"> "); if($county && $searchstring && (strcmp($county,"All")!=0)) { //Fill counties with county town names $townsql = "SELECT * FROM towns WHERE COUNTY = '$county';"; $townresults = mysql_query($townsql, $db); echo("<form name=\"townselection\" method=GET action=\"search.php\">"); echo("<input type=hidden name=\"startat\" value=0>"); echo("<input type=hidden name=\"searchstring\" value=\"".$searchstring."\">"); echo("<input type=hidden name=\"county\" value=\"".$county."\">"); echo("Search for \"".stripslashes($searchstring)."\" in: <select name=\"region\" value=\"".$region."\">"); while($townnumber>$cur) { $townname = mysql_result($townresults, $cur, 'townname'); echo("<option name=\"".$townname."\">".$townname."</option>"); $cur++; } echo("</select>"); echo("<input type=submit value=\"go\"></form><p>"); $cur=0; } echo $resultsmessage; echo $totalrecords." records found."; echo("</font></td></tr></table>"); $result=mysql_query($sql,$db) or die (mysql_error()); $num=mysql_num_rows($result); if($num==0) { } else{ while($num>$cur){ $classification=mysql_result($result,$cur,"classification"); $uniqueid=mysql_result($result,$cur,"uniqueid"); $dateadded=mysql_result($result,$cur,"dateadded"); $dateadded_timestamp=preg_replace('/[\-\: ]/', '', $dateadded); $businessname=mysql_result($result,$cur,"businessname"); $keywords=mysql_result($result,$cur,"keywords"); $address1=mysql_result($result,$cur,"address1"); $address2=mysql_result($result,$cur,"address2"); $address3=mysql_result($result,$cur,"address3"); $address4=mysql_result($result,$cur,"address4"); $phone=mysql_result($result,$cur,"phone"); $fax=mysql_result($result,$cur,"fax"); $mobile=mysql_result($result,$cur,"mobile"); $email=mysql_result($result,$cur,"email"); $website=mysql_result($result,$cur,"website"); $logo=mysql_result($result,$cur,"logo"); $recordnumberer++; if($classification==0) { echo("<center><table width=\"700\" bgcolor=\"#FFFFFF\" cellpadding=\"5\" cellspacing=\"0\">"); echo("<tr><td background=\"images/gradient.jpg\"><font class=\"headerfont\">$businessname</font></td></tr>"); echo("</table>"); echo("<table background=\"images/cardback.jpg\" width=\"700\" bgcolor=\"#FFFFFF\" cellpadding=\"5\" cellspacing=\"0\">"); echo("<tr><td width=380><font class=\"bodyfont\"><i>"); if($address1) echo("".$address1.", "); if($address2) echo("".$address2.", "); if($address3) echo("".$address3.", "); echo("County ".$address4."."); echo("</i><br><font class=\"bodyfont\"><br><b>Phone:</b> $phone </td><td valign=top width=120></td><td valign=top width=200></td></tr>"); echo("</table>"); } else if($classification==1) { echo("<center><table width=\"700\" bgcolor=\"#FFFFFF\" cellpadding=\"5\" cellspacing=\"0\">"); echo("<tr><td background=\"images/gradient.jpg\"><font class=\"headerfont\">$businessname</font></td></tr>"); echo("</table>"); echo("<table background=\"images/cardback.jpg\" width=\"700\" bgcolor=\"#FFFFFF\" cellpadding=\"5\" cellspacing=\"0\">"); echo("<tr><td width=380><font class=\"bodyfont\"><i>"); if($address1) echo("".$address1.", "); if($address2) echo("".$address2.", "); if($address3) echo("".$address3.", "); echo("County ".$address4."."); echo("</i><br><font class=\"bodyfont\"><br><b>Phone:</b> $phone <b>Fax:</b> $fax <b> Mobile:</b> $mobile<br><font class=\"bodyfont\"><b>WWW:</b> <a TARGET=\"_new\" href=\"http://$website\">$website</a><br> <b>E-mail:</b> <a href=\"mailto:$email\">$email</a><br><br></td><td valign=top width=120><font class=\"bodyfont\"><a href=\"javascript:pop_descwindow('description.php?uniqueid=$uniqueid')\"><b>more info</b></a></font></td><td valign=top width=200><center><img src=\"logos/".$logo."\" width=\"175\" height=\"75\" hspace=0 vspace=0 border=0></center></td></tr>"); echo("</table>"); } else{ echo("<center><table width=\"700\" bgcolor=\"#FFFFFF\" cellpadding=\"5\" cellspacing=\"0\">"); echo("<tr><td background=\"images/background.jpg\"><a target=\"blank\" href=\"/webpages/".$dateadded_timestamp.".htm\"><img src=\"logos/".$logo."\" vspace=0 hspace=0 border=0></a><p></td></tr>"); echo("</table>"); } $cur++; } } if($totalrecords>10){ echo("<table background=\"images/background.jpg\" width=700 bgcolor=#FFFFFF cellpadding=5 cellspacing=0><tr><td>"); for($i=0;$i<$totalrecords;$i=$i+10) { $startrecord=$i+1; $endrecord=$i+10; if($i==$startat){ echo("<font class=bodyfont><A STYLE=\"text-decoration:none\" HREF=\"search.php?startat=$i&searchstring=$searchstring®ion=$region&county=$county\">$startrecord-$endrecord</A></font> "); } else echo("<font class=bodyfont><A STYLE=\"text-decoration:underline\" HREF=\"search.php?startat=$i&searchstring=$searchstring®ion=$region&county=$county\">$startrecord-$endrecord</A> </font>"); } echo("</td></tr></table>"); } ?> <table background="images/footer.jpg" width=710 cellpadding=5 cellspacing=0 height=21> <tr><td></td></tr></table> </td></tr> </table> </body></html> Link to comment https://forums.phpfreaks.com/topic/132308-search-engine-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.