Ich habe eine relativ einfache suchabfrage für eine stockfotowebsite. Das Problem ist, dass nicht so wie gewünscht vollständige Begriffe gesucht werden sondern auch Einzelbuchstaben! Wenn ich zB a eingebe, bekomme ich im Ergebnis alle Fotos wo in der Verschlagwortung irgendwo ein a vorkommt.
Der Code:
Kann mir jemand mit diesen Angaben weiterhelfen?
Der Code:
PHP-Code:
# START SEARCH FUNCTIONALITY
$my_search = strtolower($my_search);
$my_search_words = split(" ",$my_search);
$words = count($my_search_words);
for($z = 0; $z < $words; $z++){
if(strlen($my_search_words[$z]) >= 1){
$my_search_words2 = $my_search_words2 . "," . strtolower($my_search_words[$z]);
//$my_search_words2 = "," . $my_search_words2;
}
}
$my_search_words2 = split(",",$my_search_words2);
$words2 = count($my_search_words2);
//echo $words2;
//exit;
//$my_search = "t";
if($match_type == "id"){
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and id = '" . $_POST['search'] . "'";
}
if($match_type != "id"){
if($words2 < 2){
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and keywords like '%$my_search%'";
} else {
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and (";
for($z2 = 1; $z2 < $words2; $z2++){
$searcher.= " keywords like '%" . $my_search_words2[$z2] . "%'";
if($z2 < ($words2 - 1)){
if($match_type == "any"){
$searcher.= " or ";
}
if($match_type == "all"){
$searcher.= " and ";
}
}
}
if($words2 > 0){
$searcher.= " or";
}
for($z3 = 1; $z3 < $words2; $z3++){
$searcher.= " title like '%" . $my_search_words2[$z3] . "%'";
if($z3 < ($words2 - 1)){
if($match_type == "any"){
$searcher.= " or ";
}
if($match_type == "all"){
$searcher.= " and ";
}
}
}
}
//$searcher.= "keywords like '% $my_search %' ";
$searcher.= ") order by 'cart_count' desc LIMIT 350";
}
//echo $words2;
//echo "<br /><br />";
//echo $searcher;
//exit;
//echo $searcher;
//exit;
$package_result = mysql_query($searcher, $db);
$package_rows = mysql_num_rows($package_result);
//echo "<br /><br />" . $package_rows;
//exit;
while($package = mysql_fetch_object($package_result)){
$photo_result = mysql_query("SELECT * FROM uploaded_images where reference = 'photo_package' and reference_id = '$package->id'", $db);
$photo_rows = mysql_num_rows($photo_result);
$photo = mysql_fetch_object($photo_result);
if($templine < $perpage and $line < $package_rows) {
if($line == $recordnum) {
$line++;
$templine++;
?>
<?
if($photocount == 1){
?>
</tr><tr>
<?
} else {
?>
<?
}
?>
Kommentar