This question is an exact duplicate of:
- inner join between 3 tables 3 answers
i have this query :
select * from countrysegments
inner join country on countrysegments.country_id = country.id
inner join segments on countrysegments.segment_id = segments.id
all i need to know is how to show the name of the country inside table country,
and for each country show all the segments available,nothing worked with me, if someone could help me would me great, thank u
i tried a lot with no answers,
i tried this:
select * from countrysegments
inner join country on countrysegments.country_id = country.country
inner join segments on countrysegments.segment_id = segments.segment
iknow im far from the correct answers but please can anyone help?
country_id is a foregin key of the id in country table segment_id is a foreign key of the id in segments table
my database schema:
table name: countrysegments
id country_id segment_id
table name: country
id country
table name: segments
id segment
this is in class.php:public function select(){
$stmt = $this->conn->prepare("SELECT country FROM
country") or die($this->conn->error);
if($stmt->execute()){
$result = $stmt->get_result();
return $result;
}
}
and this in index.php`
<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();
while($fetch = $read->fetch_array(MYSQLI_ASSOC)){
foreach($fetch as $field=>$value){
echo '<tr><td>' . $value . '</td>';
}
}
?>
</tbody>
</table>`
with this solution i only have the query that show me the countries but i need to show in every country all the segments available using a dropdown menu
please i need your help all