<?php
$hostname_logon = “localhost” ;
$database_logon = “” ;
$username_logon = “” ;
$password_logon = “” ;$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( “Unabale to connect to the database” );
mysql_select_db($database_logon) or die ( “Unable to select database!” );$limit = 5;
$var = @$_GET[‘q’] ;
$trimmed = trim($var);
$trimmed_array = explode(” “,$trimmed);
if ($trimmed == “”) {
$resultmsg = “<p>Search Error</p><p>Παρακαλώ εισάγετε μια αναζήτηση!</p>” ;
}if (!isset($var)){
$resultmsg = “<p>Search Error</p><p>Δεν υπάρχει παράμετρος αναζήτησης </p>” ;
}foreach ($trimmed_array as $trimm){
$query = “SELECT * FROM books WHERE title LIKE \”%$trimm%\” OR category LIKE \”%$trimm%\” OR author LIKE \”%$trimm%\” ORDER BY title DESC” ;
$numresults=mysql_query ($query);
$row_num_links_main =mysql_num_rows ($numresults);if (empty($s)) {
$s=0;
}$query .= ” LIMIT $s,$limit” ;
$numresults = mysql_query ($query) or die ( “Couldn’t execute query” );
$row= mysql_fetch_array ($numresults);do{
$adid_array[] = $row[ ‘book_id’ ];
}while( $row= mysql_fetch_array($numresults));
}if($row_num_links_main == 0 && $row_set_num == 0){
$resultmsg = “<p>Search results for:” . $trimmed .”</p><p><h2>Συγνώμη,η αναζήτηση σας δεν επέφερε κανένα αποτέλεσμα!</h2></p>” ;
}$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}?>
<?phpif( isset ($resultmsg)){
echo $resultmsg;
exit();
}else{
echo “Αναζήτηση αποτελεσμάτων: ” . $var;
}foreach($newarr as $value){
$query_value = “SELECT * FROM books WHERE book_id = ‘$value'”;
$num_value=mysql_query ($query_value);
$row_linkcat= mysql_fetch_array ($num_value);
$row_num_links= mysql_num_rows ($num_value);$titlehigh = preg_replace ( “‘($var)’si” , “<b>\\1</b>” , $row_linkcat[ ‘title’ ] );
$linkhigh = preg_replace ( “‘($var)’si” , “<b>\\1</b>” , $row_linkcat[ ‘author’ ] );
$linkdesc = preg_replace ( “‘($var)’si” , “<b>\\1</b>” , $row_linkcat[ ‘category’ ] );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);
}?>
<p>
<?php echo $titlehigh; ?>
<?php echo $linkhigh; ?><br>
<?php echo $linkdesc; ?>
</p><?php
}
if($row_num_links_main > $limit){if ($s>=1) { // do not display previous link if ‘s’ is ‘0’
$prevs=($s-$limit);
echo “<div align=’left’><a href=’$PHP_SELF?s=$prevs&q=$var&catid=$catid’>Previous ” .$limit. “</a></div>”;
}$slimit =$s+$limit;
if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
// not last page so display next link
$n=$s+$limit;
echo “<div align=’right’><a href=’$PHP_SELF?s=$n&q=$var&catid=$catid’>Next ” .$limit. “</a></div>”;
}
}
} //end foreach $newarr
?>
thanks http://www.freestuff.gr/forums/viewtopic.php?t=43617