![]() |
|
| |||||||
| Notices |
| mySQL & PHP Discussions, information and help with mySQL and PHP. |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| My domain is www.onitshabusinessdirectory.com Please what is wrong with this searching script. the error message is: Parse error: syntax error, unexpected T_STRING, expecting 'searchproduct/index.php on line 23 //after connection //specify how many result to display per page $limit=10; //Get the search variable from URL $var=@$_GET['q']; //trim whitespace from the stored variables $trimmed=trim($var); //seperate key-phrases into key words $trimmed_array=explode(" ",$trimmed); //check for an empty string and display a message. if(!isset($var)){ $resultmsg="<p>Search Error</p><p>We dont seem to have asearch parameter!</p>"; } //Build SQL Query for keyword entered for each ($trimmed_array as $trimm){ //Specify table and field names for the SQL query $query="SELECT * FROM Onitsha Product Directory WHERE Business Location LIKE\"%$TRIMM%\" OR Type of Location LIKE \"%$TRIMM%\" OR Type of Business LIKE\"%$TRIMM%\" OR Category of Business LIKE\"%$TRIMM%\" ORDER BY ID DESC"; //Execute the query to get number of rows that contain search keywords $numresults=mysql_query($query); $row_num_links_main=mysql_num_rows($numresults); //next determine if 's' has been passed to script, if not use 0. //'s' is a variable that gets set as we navigate the search result pages. if (empty($s)){ $s=0; } //now let's get the results. $query="LIMIT$s,$limit"; $numresults=mysql_query($query)or die ("Couldn't execute query"); $row=mysql_fetch_array($numresults); //store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result. do{ $adid_array[]=$row['ID']; }while($row=mysql_fetch_array($numresult)); }//end foreach if($row_num_link_main==0 &&$row_set_num==0){ $resultmsg="<p>search result for:". $trimmed. "</p><p>sorry,your search returned zero result</p>; } //delete duplicate records id's from the array. to do this we will use array_unique function $tmparr=array_unique($adid_array); $i=0; foreach ($tmparr as $v) { $newarr[$i]=$v; $i++; } //Let display the result. But first will will display the serch form on the top of the page ?> <form action="search.php" method="get" name="search"> <div align="center"> <input name="q" type="text" value=<?php echo $q; ?> "size="15"> <input name="search" type=" submit value="search"> </div> </form> <?php //display what the person searched for if(isset($resultmsg)){ echo $resultmsg; exit(); " }else{ echo "Search result for: ".$var; } foreach($newarr as $value){ //specify table and field names for the SQL query $query_value="SELECT *FROM Onitsha Product Directory WHERE ID='$value'"; $num_value=mysql_query($query_value); $row_linkcat=mysql_fetch_array ($num_value); $row_num_link=mysql_num_rows($num_value); //making keywords bold $titlehigh=preg_replace("'($var)'si","<b>\\1</b>",$row_linkcat['Business Location']); $linkhigh=preg_replace("'($var)'si","<b>\\1</b>",$row_linkcat['Type of Location']); $linkdesc=preg_replace("'($var)'si","<b>\\1</b>",$row_linkcat['Business Location']); $titlehigh=preg_replace("'($var)'si","<b>\\1</b>",$row_linkcat['Type of Business']); $titlehigh=preg_replace("'($var)'si","<b>\\1</b>",$row_linkcat['Category of Business']); foreach($trimmed_array as $trimm){ if($trimm !='b'){ $titlehigh=preg_replace("'($trimm)'si","<b>\\1</b>",$titlehigh); $linkhigh=preg_replace("'($trimm)'si","<b>\\1</b>",$linkhigh); $linkdesc=preg_replace("'($trimm)'si","<b>\\1</b>",$linkdesc); $titlehigh=preg_replace("'($trimm)'si","<b>\\1</b>",$titlehigh); } //end highlight ?> <p> <?php echo $titlehigh;?><br> <?php echo $linkhigh;?><br> <?php echo $linkhigh;?> </p> <?php }//end for each $trimmed_array if ($row_num_link_main>$limit){ //next we need to do the links to other search result pages if ($s>1){//do not display previous link if 's' is'0' $prevs=($s-$limit); echo "<div align='left'>a href='$PHP_SEL?s=$prevs&q=$var&catid'>Previous" .$limit. "</a></div>"; } //check to see if last page $slimit=$s+$limit; if(!($slimit>=$row_num_links_main)&& $row_num_links_main!=1) { //not lat page so display next page $n=$s+$limit; echo"<div align='right'><a href='$PHP_SELF?s=$var&catid'>next" .$limit. "</></div>"; } } } //end foreach $newarr ?> |