Php 在从postgresql db读入的表的最后一行中添加复选框列

Php 在从postgresql db读入的表的最后一行中添加复选框列,php,html,postgresql,checkbox,html-table,Php,Html,Postgresql,Checkbox,Html Table,我有一个从postgresql数据库读取的表。我在将复选框添加到表中的最后一行时遇到问题,因此我可以使用addtobasket函数将项目传递到basket.php文件 首先,我需要在每一行的最后一列中添加一个复选框,以便在单击“添加到购物车”时可以对照要添加的项目进行检查。我正在为此苦苦挣扎。任何帮助将不胜感激,因为我的代码如下。如果你能解释一下需要做什么,那就太棒了,我可以从中学到这一点 <table border="1"> <tr> <t

我有一个从postgresql数据库读取的表。我在将复选框添加到表中的最后一行时遇到问题,因此我可以使用addtobasket函数将项目传递到basket.php文件

首先,我需要在每一行的最后一列中添加一个复选框,以便在单击“添加到购物车”时可以对照要添加的项目进行检查。我正在为此苦苦挣扎。任何帮助将不胜感激,因为我的代码如下。如果你能解释一下需要做什么,那就太棒了,我可以从中学到这一点

    <table border="1">
    <tr>
    <th>ref</th>
    <th>title</th>
    <th>platform</th>
    <th>description</th>
    <th>price</th>
    <th>select</th>
    </tr>

<?php $resource = pg_query ($connect, "select refnumber,title,platform,description,price from csgames");
        while ($a = pg_fetch_array ($resource)) {
            echo "<tr>";
            for ($j = 0; $j < pg_num_fields ($resource); $j++) {
                echo "<td>".$a[$j] ."</td>";
            }
            echo "</tr>";
        }


    ?>
    </table>

裁判
标题
平台
描述
价格
选择
试试这个

while ($a = pg_fetch_array ($resource)) {
   echo "<tr>";
   for ($j = 0; $j < pg_num_fields ($resource); $j++) {
      echo "<td>".$a[$j] ."</td>";
   }
   echo '<input type="checkbox" name="items[]" value="'.$id.'" />'; //replace with item id
   echo "</tr>";
}
$items = $_POST['items']; //array of itemid selected

output
---------
var_dump(items) = Array ( [items] => Array ( [0] => item123 [1] => item125 ) )