首先我会告诉我想实现什么,然后我会解释我是如何尝试这样做的。 我有两张表,一个商店类型的船只有一个描述和他们自己的Id。然后我有另一个表格,其中船只类型已被存储为文本。我的目标是用两个复选框选择每一个(两个表中都有记录),并在表2中存储表1中的Id。 我将介绍数据以提供帮助。 表1
1|Balandra|Some description 2|Bergantin|Some description 3|Whatever |Whatever.....
从多个表获取php复选框数据
表2 Balandra Bergantin Whatever
然后,我已创建一个PHP页面显示与我上面提到的复选框两个表。复选框存储Table1 Id和Table2 vesseltypename。
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo $navio['typevessel']; ?> class="btn btn-default"><em class="fa fa-arrow-circle-o-left"></em></a>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
因此,我想检查两个表记录并将table1 Id存储在table2 idtypevessel字段中。 我认为,一个PHP文件可以存储两个项目,并呼吁与这些参数的更新功能,像这样:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
任何建议,因为我认为我必须做一个按钮来提交这个参数,但它必须在两张桌子上工作,我不知道如何同时访问两个foreach
循环。 在此先感谢。
请删除postgres标签 –
完成!我认为这可能是有用的,因为我连接到PostgreSQL数据库,但实际上是不必要的。谢谢! –