Danke für die Antwort. Jetzt ist es Arbeit, aber ich habe nächstes Problem. ich neu gemacht, ein Verfahren Datensätze aus der Datenbank anzuzeigen:geben Sie einen Datensatz aus der Datenbank
public $id, $nazwa, $quantity, $data, $godzina, $sn, $added, $kategoria, $numrows;
public function magazyn() {
$resultmag = $this->magazyn = $this->conn->prepare("SELECT * FROM `products` ORDER BY `id`");
$resultmag = $this->conn->set_charset("utf8");
$resultmag = $this->magazyn->execute();
$resultmag = $this->magazyn->get_result();
if ($isset = $resultmag->num_rows > 0) {
while ($row = $resultmag->fetch_object()) {
$this->id = $row->id;
$this->nazwa = $row->nazwa;
$this->quantity = $row->quantity;
$this->data = $row->data;
$this->godzina = $row->godzina;
$this->sn = $row->sn;
$this->added = $row->added;
$this->kategoria = $row->kategoria;
}
$this->numrows = $resultmag->num_rows;
} else {
echo "No results database";
}
}
function __toString() {
return (string) $this->numrows;
}
//-------------------------------
$mag = new Magazyn();
$mag->magazyn();
?>
<table class="table table-bordered">
<tr><th style='text-align:center'>ID</th><th style='text-align:center'>DODAŁ</th><th style='text-align:center'>NAZWA</th><th style='text-align:center'>KATEGORIA</th><th style='text-align:center'>SERIAL</th><th style='text-align:center'>ILOŚĆ</th><th style='text-align:center'>DATA</th><th style='text-align:center'>GODZINA</th><th style='text-align:center' colspan='2'>AKCJA</th></tr>
<?php
$color = NULL;
$color1 = '#99bbff';
$color2 = '#b3ccff';
$color == $color1 ? $color = $color2 : $color = $color1;
echo "<tr class='active'>";
echo "<td align='center' style='background-color:" . $color . ";'>" . $mag->id . "</td>";
echo "<td align='center' style='background-color:" . $color . ";'><a href='panel.php?page=userpanel&user=" . $mag->added . "'>" . $mag->added . "</a></td>";
echo "<td align='center' style='background-color:" . $color . ";'>" . $mag->nazwa . "</td>";
echo "<td align='center' style='background-color:" . $color . ";'><a href='panel.php?page=category&cat=" . $mag->kategoria . "'>" . $mag->kategoria . "</a></td>";
echo "<td align='center' style='background-color:" . $color . ";'><a href='panel.php?page=editserial&sn=" . $mag->sn . "'>" . $mag->sn . "</a></td>";
echo "<td align='center' style='background-color:" . $color . ";'>" . $mag->quantity . "</td>";
echo "<td align='center' style='background-color:" . $color . ";'>" . $mag->data . "</td>";
echo "<td align='center' style='background-color:" . $color . ";'>" . $mag->godzina . "</td>";
echo "<td align='center'><a href='panel.php?page=magazyn&action=edit&sn=" . $mag->sn . "&nazwa=" . $mag->nazwa . "&kategoria=" . $mag->kategoria . "&id=" . $mag->id . "'</a><button class='btn btn-default'>Edytuj</button></td>";
echo "<td align='center'><a href='panel.php?page=magazyn&action=delete&sn=" . $mag->sn . "'</a><button class='btn btn-default'>Usuń</button></td>";
echo "</tr>";
Das Problem ist, dass es zeigt nur einen Datensatz aus der Datenbank. Als ich während Echo hinzu:
while ($row = $resultmag->fetch_array()) {
echo $this->id = $row['id'];
echo $this->nazwa = $row['nazwa'];
echo $this->quantity = $row['quantity'];
echo $this->data = $row['data'];
echo $this->godzina = $row['godzina'];
echo $this->sn = $row['sn'];
echo $this->added = $row['added'];
echo $this->kategoria = $row['kategoria'];
}
Zeigt alle Datensätze, sondern durch:
$mag->magazyn();
Also ... Was ist die Frage? Wie viele Datensätze sollte es anzeigen? – Mike
überschreiben Sie Ihre Variablen in der Schleife, sollten Sie wahrscheinlich ein multidimensionales Array der Ausgabe machen –
die Frage ist: Wie gebe ich Datensätze in der Tabelle zurück (