i have these tables in database:
country: id country
and i have segment table:
segments: id segment
and the third table named countrysegments have foreign key: country id related to country.id and segment_id related to country.id
countrysegments: id country_id segment_id
in index.php i have this:
<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>
i have inner join the three tables like this in 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;
}
}
the question is that i have to insert into countrysegment table what everycountry have choose as segment
just i need help of the query and how might it done thank u