首先我會告訴我想實現什麼,然後我會解釋我是如何嘗試這樣做的。 我有兩張表,一個商店類型的船隻有一個描述和他們自己的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數據庫,但實際上是不必要的。謝謝! –