tushkanwn |
05.01.2011 17:53:50 |
Datensätzen in Tabellen ausgeben. Eine Zeile fehlt!
Hallo! Habe folgendes Problem: habe mir ein Suchformular mit einer Suchfunktion gebastelt, die die gesamte Datenbank nach einem Suchbegriff durchsucht und die Ergebnisse in Tabellen ausgibt. Es funzt alles soweit, nun fehlt immer ein Datenzatz in jeder Tabelle.
D.h. wenn es drei Einträge in der Tabelle 'kostenstelle' vorhanden sind werden nur zwei davon ausgegeben. In je Tabelle wird die erste Zeile immer leer ausgegeben, die anderen sind befüllt.
Wie kann ich diese erste Zeile mit meinem Datensatz befüllen?
Bitte um Hilfe!
Hier ist der Code:
PHP-Code:
function mysqlSearch($volltext)
{
// replace multiple whitespaces with a simple blank
$aSearch = explode(' ', preg_replace('#\s+#', ' ', $volltext));
// count search words once
$iSearch = count($aSearch);
if ($iSearch == 0) {
return array();
}
// remove addslashes (automatically executed by php) and use mysql_real_escape_string instead. it's more secure against sql injection
if (get_magic_quotes_gpc()) {
$aSearch = array_map('stripslashes', $aSearch);
}
$aSearch = array_map('mysql_real_escape_string', $aSearch);
// get all tables in selected database
$sSQL1 = 'SHOW TABLES';
$rRes1 = mysql_query($sSQL1);
// save hits
$aHits = array();
while ($aTable = mysql_fetch_array($rRes1)) {
$sTable = $aTable[0];
// get all columns from each table
$sSQL2 = "SHOW COLUMNS FROM `$sTable`";
$rRes2 = mysql_query($sSQL2);
// combine search words with columns
$aPermutation = array();
while ($aColumn = mysql_fetch_assoc($rRes2)) {
$sColumn = $aColumn['Field'];
for ($i = 0; $i < $iSearch; $i++) {
$volltextword = $aSearch[$i];
$aPermutation[] = "MATCH($sColumn) AGAINST ('.%$volltext%.' IN BOOLEAN MODE)";
echo $str;
}
}
// combine as OR-condition
$sSQL4 = "SELECT * FROM `$sTable` WHERE " . implode(' OR ', $aPermutation);
$rRes4 = mysql_query($sSQL4);
// collect result
while ($aHit = mysql_fetch_assoc($rRes4)) {
$total_cols = count($aHit);
$aHits[$sTable][] = $aHit;
print "<HTML><BODY>";
print "<br></br>";
print "<p><table width='40%' border='1' cellspacing='0' cellpadding='0' align='left'>";
print "<tr><td colspan=$total_cols align=center><b>".$sTable."</b> </td> </tr>";
$sSQL2 = "SHOW COLUMNS FROM `$sTable`";
$rRes2 = mysql_query($sSQL2);
while ($aColumn = mysql_fetch_assoc($rRes2)) {
$sColumn = $aColumn['Field'];
print "<td>";
print $sColumn." ";
print "</td>";
}
print "<tr>";
$y=0;
while($y < $total_cols){
print "<td>";
print $row[$y]." ";
print "</td>";
$y++;
}
print "</tr>";
while($row = mysql_fetch_row ($rRes4)) {
$y = 0;
print "<tr>";
while($y < $total_cols){
print "<td>";
print $row[$y]." <br>";
print "</td>";
$y++;
}
print "</tr>";
}
print "</TABLE></BODY></HTML>";
print "<br></br>";
print "<br></br>";
// var_dump($aHit);
}
}
print "<br>";
// return $aHits;
}
echo mysqlSearch($volltext);
}
var_dump($aHit) zeigt mir die fehlenden Einträge!
|