私は父のショップのために在庫管理ソリューションをPHPで構築しています。これは、MySQLデータベースからテーブル内の在庫を一覧表示するコードです。私も、「productdetails.php」に移動するものを、ボタン(フォームやボタンクラス)を入れて、変数として現在の行のバーコードを渡すことができますどのようにボタンを作成して次のページに変数を渡すもの
<?php
$sql = "SELECT * FROM inventory";
$res = mysqli_query($conn, $sql) or die ('Wrong statement!');
echo '<table border=1>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Type</th>';
echo '<th>Name</th>';
echo '<th>Wholesaleprice</th>';
echo '<th>Price</th>';
echo '<th>Supplier</th>';
echo '<th>Place</th>';
echo '<th>Place2</th>';
echo '<th>Count</th>';
echo '<th>Barcode</th>';
echo '<th>Last Change</th>';
echo '<th>Details</th>
echo '</tr>';
while (($current_row = mysqli_fetch_assoc($res))!= null) {
echo '<tr>';
echo '<td>' . $current_row["ID"] . '</td>';
echo '<td>' . $current_row["type"] . '</td>';
echo '<td>' . $current_row["name"] . '</td>';
echo '<td>' . $current_row["wholeprice"] . '</td>';
echo '<td>' . $current_row["price"] . '</td>';
echo '<td>' . $current_row["wholesaler"] . '</td>';
echo '<td>' . $current_row["whereis"] . '</td>';
echo '<td>' . $current_row["whereis2"] . '</td>';
echo '<td>' . $current_row["count"] . ' ' . $current_row["dimension"] . '</td>';
echo '<td>' . $current_row["barcode"] . '</td>';
echo '<td>' . $current_row["lastchange"] . '</td>';
echo '<td> HERE GOES THE BUTTON </td>';
echo '</tr>';
}
echo '</table>';
mysqli_free_result($res);?>
?
私が試した:
<form action="productdetails.php" method="get">
<button type="submit" class="button" value="' . $current_row["barcode"] . '">Product Details</button>
</form>
使用するJavaScript。パラメータを引数として受け取り、ボタンクリックで関数を呼び出すJavaScriptでの関数の書き込み。 – Naincy