:]]'; } return $out; } function search_perform($terms){ // main function that will see the table from results $terms = search_split_terms($terms); // split the words $terms_db = search_db_escape_terms($terms); $terms_rx = search_rx_escape_terms($terms); $parts = array(); foreach($terms_db as $term_db){ mysql_connect("localhost","root",""); mysql_select_db("uniuob") or die("Unable to select database"); $parts[] = "desc_en RLIKE '$term_db'"; } $parts = implode('AND ', $parts); $sql = "SELECT * FROM pictures WHERE $parts"; $rows = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ // fetch array // what is the diffrents between fetch array and fetch row??? $row[score] = 0; foreach($terms_rx as $term_rx){ $row[score] += preg_match_all("/$term_rx/i", $row[content_body], $null); } $rows[] = $row; } uasort($rows, 'search_sort_results'); return $rows; } function search_rx_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '\b'.preg_quote($term, '/').'\b'; } return $out; } function search_sort_results($a, $b){ $ax = $a[score]; $bx = $b[score]; if ($ax == $bx){ return 0; } return ($ax > $bx) ? -1 : 1; } function search_html_escape_terms($terms){ $out = array(); foreach($terms as $term){ if (preg_match("/\s|,/", $term)){ $out[] = '"'.HtmlSpecialChars($term).'"'; }else{ $out[] = HtmlSpecialChars($term); } } return $out; } function search_pretty_terms($terms_html){ if (count($terms_html) == 1){ return array_pop($terms_html); } $last = array_pop($terms_html); $rrr= implode(',', $terms_html)."\tand\t"."$last"; // the words that i entered return $rrr; } # do the search here... taken from the text before $var = $HTTP_GET_VARS[q] ; $search = trim($var); // delete spaces before and after the word $results = search_perform($search); $sell =count($results); echo "$sell\t\t\t\t\t\t"; // print the number of results found $call = search_split_terms($search); $call2 = search_html_escape_terms($call); $call3 = search_pretty_terms($call2); echo "$call3"; // the words for searching //Q: how to show the records //Q: if i put a senetence with one word that is not in the table but the others are there it will say 0 results // how to show that there are results for the other words even if there is one word not there. ?>