我有这些表中的数据库:插入到连接表的mysqli接力
country: id country
和我有段表:
segments: id segment
和第三台名为countrysegments有外键:国家ID相关与country.id相关的country.id和segment_id
countrysegments: id country_id segment_id
in index.php我有这个:
<div class="col-md-12">
<table id="tbl" class = "table table-bordered table-responsive ">
<thead>
<th class="text-center">country</th>
<th class="text-center">segments</th>
</thead>
<tbody>
<?php
require 'class.php';
$conn = new db_class();
$read = $conn->select();
$test = $conn->read();
while($fetch = $read->fetch_array()){
?>
</td><td><select name="" id="">
<?php
$reads = $conn->read();
while($fetch = $reads->fetch_array()){
?>
<option><?php echo $fetch['segment']?></option>
<?php }?>
</select>
</td> </tr>
<?php }
?>
</tbody>
</table>
<form action="activate.php" method="post">
<button class="btn btn-danger" name="save">Save</button>
我有内部联接三个表像这样class.php:
public function selectFrom(){
$stmt = $this->conn->prepare("select * from countrysegments
inner join country on countrysegments.country_id = country.id
inner join segments on countrysegments.segment_id = segments.id") or die($this->conn->error);
if($stmt->execute()){
$result = $stmt->get_result();
return $result;
}
}
的问题是,我必须插入countrysegment表什么everycountry有选择的段
只是我需要查询的帮助和如何才能完成它感谢ü
ü可以格式化代码 –
你能告诉什么需要插入countrysegments表中。 或显示表的所期望的结果。 – Mack4Hack
每个国家都必须有一个片段,所以我必须插入该国的ID和表countrysegments @ Mack4Hack – eddy