感謝您的回答。現在是工作,但我有下一個問題。 我重拍的方法從數據庫中顯示的記錄:從數據庫返回一條記錄
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>";
的問題是,它顯示只有一個記錄從數據庫中。 當我加入,而回聲:
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'];
}
顯示的所有記錄,但通過:
$mag->magazyn();
那麼......問題是什麼?它應該顯示多少條記錄? – Mike
你在循環中覆蓋你的變量,你應該做出一個多維數組的輸出 – 2016-05-17 21:59:02
的問題是:我如何返回表中的記錄(