Hallo zusammen...
ich habe in einem Script folgenden Quelltext:
<?php
// Daten auslesen
$r1 = MySQL_QUERY("SELECT * FROM $cat ORDER BY id ASC");
// Ausgabe
while ($d1= mysql_fetch_array($r1)) {
$gesamtlinks = mysql_query("SELECT count(*) as gesamtlinks from $links WHERE bereich='$d1[id]'");
$gesamtlinks = mysql_fetch_array($gesamtlinks);
echo "<table border=0 cellspacing=1 cellpadding=0 bgcolor=#000000>";
echo "<tr><td>";
echo "<table border=0 cellpadding=2 cellspacing=0 class=content width=300>";
echo "<tr><td bgcolor=#999999 class=content><img src=../../images/shared/wl_klein.gif> <a href='detail.php?cat=".$d1[id]."' class='Link'>".$d1[titel]."</a> (".$gesamtlinks[0]." Links - ".$d1[hits]." Hits)</td></tr>";
echo "</table>";
echo "</td></td></table><br>";
}
?>
Nun möchte ich allerdings die Tabellen nicht untereinander ausgeben, sondern jeweils 2 in einer Zeile und dann die nächsten beiden. Wie mache ich das ???
Danke für eure Hilfe !!!
Radium2k
07-08-2002, 14:48
probier das mal :
<?php
// Daten auslesen
$r1 = MySQL_QUERY("SELECT * FROM cat ORDER BY id ASC");
// Ausgabe
$tr = "0";
while ($d1= mysql_fetch_array($r1)) {
++$tr;
$gesamtlinks = mysql_query("SELECT count(*) as gesamtlinks from $links WHERE bereich='$d1[id]'");
$gesamtlinks = mysql_fetch_array($gesamtlinks);
echo "<table border=0 cellpadding=2 cellspacing=0 class=content width=300>";
if ($tr = "2") { echo "<tr>"; }
echo "<td bgcolor=#999999 class=content><img src=../../images/shared/wl_klein.gif> <a href='detail.php?cat=".$d1[id]."' class='Link'>".$d1[titel]."</a> (".$gesamtlinks[0]." Links - ".$d1[hits]." Hits)</td>";
if ($tr = "2") { echo "</tr>"; $tr = "0"; }
echo "</table>";
}
?>
Gute Idee...aber klappt bei mir leider nicht :-(
<?php
// Daten auslesen
$r1 = MySQL_QUERY("SELECT * FROM cat ORDER BY id ASC");
// Ausgabe
$tr = 0;
while ($d1= mysql_fetch_array($r1)) {
$tr++;
$gesamtlinks = mysql_query("SELECT count(*) as gesamtlinks from $links WHERE bereich='$d1[id]'");
$gesamtlinks = mysql_fetch_array($gesamtlinks);
echo "<table border=0 cellpadding=2 cellspacing=0 class=content width=300>";
if ($tr == 2) { echo "<tr>"; }
echo "<td bgcolor=#999999 class=content><img src=../../images/shared/wl_klein.gif> <a href='detail.php?cat=".$d1[id]."' class='Link'>".$d1[titel]."</a> (".$gesamtlinks[0]." Links - ".$d1[hits]." Hits)</td>";
if ($tr == 2) { echo "</tr>"; $tr = 0; }
echo "</table>";
}
?>
Hmm...danke...habe ich jetzt auch probiert und bekomme folgende Meldung:
Warning: Supplied argument is not a valid MySQL result resource in C:\Xitami\webpages\XXX\XXX\links.php on line 120
Und nun ?
Wo ist Zeile 120?
An den Selects udgl hat sich nix geändert.
Ich habe lediglich am Vorschlag von Radium2k eine kleine Korrektur vorgenommen, anstatt if ($tr = "2") -> if ($tr == 2), damit die Tags <tr> und </tr> ausgegeben werden. Diese Ifs haben aber sicher keinen Einfluß auf den Selectstring
Sorry...
das ist Zeile 120:
$tr = 0;
Diese Zeile hat aber mit einer Fehlermeldung wie "Warning: Supplied argument is not a valid MySQL result resource in C:\Xitami\webpages\XXX\XXX\links.php on line 120" nix zu tun!
Schau bitte nochmal genau
So...
den Fehler habe ich nun alleine gefunden...hatte im SQL-String den falschen Tabellenname :-(
Allerdings gibt das Script die Daten immernoch untereinander aus und nicht wie gewünscht 2 nebeneinander und darunter dann die nächsten 2.
Ich verzweifle noch...
Post mal was Du jetzt hast
Naja...eigentlich genau das was du geschrieben hast:
<?php
// Daten auslesen
$r1 = MySQL_QUERY("SELECT * FROM $cat ORDER BY id ASC");
// Ausgabe
$tr = 0;
while ($d1= mysql_fetch_array($r1)) {
$tr++;
$gesamtlinks = mysql_query("SELECT count(*) as gesamtlinks from $links WHERE bereich='$d1[id]'");
$gesamtlinks = mysql_fetch_array($gesamtlinks);
echo "<table border=0 cellpadding=2 cellspacing=0 class=content width=300>";
if ($tr == 2) { echo "<tr>"; }
echo "<td bgcolor=#999999 class=content><img src=../../images/shared/wl_klein.gif> <a href='detail.php?cat=".$d1[id]."' class='Link'>".$d1[titel]."</a> (".$gesamtlinks[0]." Links - ".$d1[hits]." Hits)</td>";
if ($tr == 2) { echo "</tr>"; $tr = 0; }
echo "</table>";
}
?>
Nun denn, ich hoffe jetzt klappt es ....
<?php
// Daten auslesen
$r1 = MySQL_QUERY("SELECT * FROM cat ORDER BY id ASC");
// Ausgabe
$tr = 0;
echo "<table border=0>";
while ($d1= mysql_fetch_array($r1)) {
$gesamtlinks = mysql_query("SELECT count(*) as gesamtlinks from $links WHERE bereich='$d1[id]'");
$gesamtlinks = mysql_fetch_array($gesamtlinks);
$tr++;
if ($tr == 1) {
echo "<tr>";
}
echo "<td>";
echo "<table border=0 cellpadding=2 cellspacing=0 class=content width=300>";
echo "<td bgcolor=#999999 class=content><img src=../../images/shared/wl_klein.gif> <a href='detail.php?cat=".$d1[id]."' class='Link'>".$d1[titel]."</a> (".$gesamtlinks[0]." Links - ".$d1[hits]." Hits)</td>";
echo "</table>";
echo "</td>";
if ($tr == 2) {
echo "</tr>";
$tr = 0;
}
}
if ($tr == 1) {
echo "</tr>";
}
echo "</table>";
?>
Super....danke...das Ergebnis gefällt mir richtig gut...:)