rernanded
Erfahrenes Mitglied
Hallo, ich versuche Ausgaben per php in einem grid mit drei Spalten. Das funktioniert auch ganz okay. Auffallend ist nur, dass horizontal zwischen der Ausgabe in der linken und mittleren Spalte der Abstand kleiner ist als in der Ausgabe zwischen der mittleren und rechten Spalte.
Frage: Gibt es dafür eine Ursache in meinem Code?
Frage: Kann ich das Ganze auch anders und ev. besser lösen als mit num_cols?
MONI
Frage: Gibt es dafür eine Ursache in meinem Code?
Frage: Kann ich das Ganze auch anders und ev. besser lösen als mit num_cols?
MONI
PHP:
<!DOCTYPE html>
<html>
<head>
<style>
.tables {
width: 100%;
}
.trs {
}
.tds {
font-family: arial;
font-size: 20px;
text-align: center;
width: 30%;
background-color: yellow;
border-top: 0px solid #FFF;
border-bottom: 30px solid #FFF;
border-left: 0px solid #FFF;
border-right: 0px solid #FFF;
}
</style>
</head>
<body>
<?php
$servername = "localhost:3306";
$username = "";
$password = "";
$dbname = "";
$connection = new mysqli($servername, $username, $password, $dbname);
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
$sql = "SELECT * FROM datenbank ORDER BY RAND() LIMIT 0,100";
$result = $connection->query($sql);
$total_records = $result->num_rows; // the number of records
while($row = $result->fetch_array()) { // store all records
$datarows[] = $row;
}
$num_cols = 3; // the number of columns
$num_rows = ceil($total_records / $num_cols); // the number of rows
$num = 0; // don't change
echo "<table class=\"tables\">\n";
// loop for the table rows
for ($rows = 0; $rows < $num_rows; $rows++) {
echo "<tr class=\"trs\">\n";
// this is the loop for the table columns
for ($cols = 0; $cols < $num_cols; $cols++) {
if ($num < $total_records) { // show records if available
$id = $datarows[$num]['id'];
$url = $datarows[$num]['url'];
$inhalt = $datarows[$num]['inhalt'];
echo "<td class=\"tds\"><strong>".$id."</strong><br />".$url."<br />".$inhalt."<td>\n";
} else { // show an empty cell
echo "<td> </td>\n";
}
$num++; // raise the number by one for the next record
}
echo "</tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
Zuletzt bearbeitet: