Hallo,
ich habe mir eine Datenbanksuche zusammengebastelt und will jetzt eine Blätterfunktion (ab 10 Ergebnisse) hinzufügen.
Die Such funktioniert super - nur das Limit (Ergebnisse) wird nicht eingehalten.
Hat jemand eine Idee?
Jürgen
ich habe mir eine Datenbanksuche zusammengebastelt und will jetzt eine Blätterfunktion (ab 10 Ergebnisse) hinzufügen.
Die Such funktioniert super - nur das Limit (Ergebnisse) wird nicht eingehalten.
Code:
<font face="tahoma" size="4"> <font face="Verdana, Arial, Helvetica, sans-serif">Mysql
Search</font></font>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<font face="Verdana, Arial, Helvetica, sans-serif"> Specific Word or Phrase
<input type="text" name="words" value="<?php echo($words); ?>">
<br>
<br>
<input type="hidden" name="good" value="yes">
<input type="submit" value="Search">
</font>
</form>
<p><font face="Verdana, Arial, Helvetica, sans-serif"><br>
<br>
<?
if($_POST['good']=='yes')
{
echo("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>Results for $words</b></font><br><br>");
$location = "localhost"; // database host (localhost)
$username = "webxxx"; // mysql username
$password = "xxx"; //mysql password
$database = "webxxx_1"; //mysql database name
$db_table = "affilinet_shop"; // mysql table name to search
$mysql_row = "Description_short"; // This is the row in your mysql database that you want to search for text in.
$start = (isset($start)) ? abs((int)$start) : 0;
$limit = 10; // Datensätze pro Ausgabeseite
// Feststellen der Anzahl der verfügbaren Datensätze.
$resultID = @mysql_query("SELECT COUNT(ID) FROM ".$db_table);
$total = @mysql_result($resultID,0);
// Ggf. $start korrigieren (falls Parameter in
// der URL manipuliert wurde)
$start = ($start >= $total) ? $total - $limit : $start;
$query = "SELECT * FROM ".$db_table." LIMIT ".$start.",".$limit;
$resultID = @mysql_query($query);
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "ALTER TABLE $db_table ORDER BY id DESC";
$result = mysql_query($query); // bad coding yes ;)
$query = "SELECT * FROM $db_table";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
if(preg_match("/$words/i", $row[$mysql_row]))
{
$rawTitle = ($row[Title]);
$rawDeepLink1 = ($row[DeepLink1]); //yes strange variable names. It works so it doesnt matter.
$rawDescription = ($row[Description]); //T just grab extra data to be added with the search tool
$rawDisplayPrice = ($row[DisplayPrice]);
$rawProductCategoryName = ($row[ProductCategoryName]);
$rawKeywords = ($row[Keywords]);
$rawImg120_url = ($row[Img120_url]);
$rawImg_url = ($row[Img_url]);
$newnews = preg_replace("/$words/i", "<b><font color=\"red\">$words</font></b>", $row[$mysql_row]);
$display = '<H2 font face="tahoma" font-size: 13pt><b><a href=' . $rawDeepLink1 . ' TARGET=_blank TITLE="' . $rawTitle . '" STYLE="text-decoration: none"> ' .$rawTitle . ' </a> <a href=' . $rawDeepLink1 . ' TARGET=_blank TITLE="' . $rawKeywords . '" STYLE="text-decoration: none"> ' .$rawDisplayPrice . ' </a></b><br><font face="tahoma" size="2">' . $newnews . '<br><a href=' . $rawDeepLink1 . ' TARGET=_blank TITLE="' . $rawProductCategoryName . '" STYLE="text-decoration: none">Kategorie: ' .$rawProductCategoryName . ' </a> <a href=' . $rawImg_url . ' TARGET=_blank TITLE="' . $rawDescription . '" STYLE="text-decoration: none">Foto</a> <a href=' . $rawDeepLink1 . ' TARGET=_blank TITLE="' . $rawDescription_short . '" STYLE="text-decoration: none">Mehr Infos</a> <a href=' . $rawDeepLink1 . ' TARGET=_blank TITLE="' . $rawTitle . '" STYLE="text-decoration: none"> >>>> Zum Shop</a></font></H2>';
echo($display);
$foundcount++;
}
$totalcount++;
}
if(is_null($foundcount)){$foundcount=0;}
echo("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>$foundcount Treffer für: $words</b></font>");
}
if ($start > 0)
{
$newStart = ($start - $limit < 0) ? 0 : ($start-$limit);
echo "<a href=".$_SERVER['PHP_SELF']."?start=".$newStart
."><< zurück</a>";
}
if ($start + $limit < $total)
{
$newStart = $start + $limit;
echo " <a href=".$_SERVER['PHP_SELF']."?start=".$newStart
.">vor >></a>";
}
?>
Hat jemand eine Idee?
Jürgen