Hallo,
ich hab hier mal den code für eine suchfznktion gepostet, welche ich benutze. es funktionniert auch alles einwandfrei. nur leider wird mir bei der suche nur immer ein eintrag gezeigt. egal ob gleiche einträge in der datenbank hinterlegt sind, es wird immer nur einer angezeigt.
woran liegt denn das? ich bin aus dem code nicht schlau geworden:
suche.php
PHP-Code:
<?php
include("inc/db.php");
if ($_GET['suche'] == "2") {
if (isset($_POST['suchen'])){
$suchbegriff = $_POST['suchbegriff'];
$teilstr = explode(" ",$suchbegriff);
global $suchstring;
foreach ($teilstr as $ausgabe) {
$suchstring.= " $art LIKE '%$ausgabe%' AND";
}
$laenge = strlen($suchstring);
$suchstring = substr($suchstring,0,$laenge-4);
$erg_suche = mysql_query("SELECT * FROM tbl_gewerbe WHERE $suchstring",$db);
if (mysql_num_rows($erg_suche)=="") {
echo "<p class=text>Es liegen leider keine Ergebnisse für Ihre Suche vor!</p><br>";
} else {
echo "<p class=text><a href='gewerbe.php?do=detail&id=".mysql_result($erg_suche, 0,"g_id")."'>".mysql_result($erg_suche, 0,"g_gwname")."</a></p>";
}
}
}
}
?>
eingabe.htm
<form action="?do=prosearch&suche=2" method="post" name="suche" id="suche"><p class="text">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150px">Suche nach:</td>
<td width="250px"><select name="art" size="1">
<option value="g_gwname">Gewerbename</option>
<option value="g_plz">PLZ</option>
<option value="g_ort">Ort</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Suchbegriff:</td>
<td><input name="suchbegriff" type="text" id="suchbegriff" value="<?php echo $_POST["suchbegriff"];?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="suchen" type="submit" id="suchen" value="Suchen"></td>
</tr>
</table>
</p></form>
cu
hallmi