I have the code below, but my problem is i received PHP Notice: Undefined offset: (from 1 to 7) error message and what is very important for me to get country ID only once with the max number. its counting the number of projects and increase everytime one which is correct and what i need, but need to display it only once how does it display the correct result show be similar to: the correct result
here is my code:-
<table>
<tr>
<th>Country ID</th>
<th>Country Name</th>
<th>Number of Place</th>
</tr>
<?php
$country_counts=[];
$count_country =0;
$country_count_each=0;
$ids=array();// Store unique country_id values here
foreach( $projects as $project ) {
$country_id = $project['Project']['country_id'];
# Check if the country_id is NOT in the array and display if OK.
if( isset( $country_counts[ $country_id ] ) || !in_array( $country_id, $ids ) ) {
$country_counts[$country_id]++;
$country_count_each = $project['Project']['country_id'];
if($project['Project']['country_id']==$country_count_each){
$count_country+=$country_count_each;
$ids[]=$country_id;
//echo $country_counts[$country_id];
?>
<tr>
<td style="width: 30%"><?php echo $project['Project']['country_id']; ?></td>
<td style="width: 30%"><?php echo 'Country Name'; ?></td>
<td style="width: 30%"><?php echo $country_counts[$project['Project']['country_id']]; ?></td>
</tr>
<?php
}
}else {
$country_counts[$country_id] =$country_id;
}
}
$proects_num = count($projects);
?>
</table>
<?php
echo '<br>' .'Total projects numbers are: ' . $proects_num .'<br>';
echo $html->link('Home ', $this->webroot.'countries/index/');
?>
the table in database Table of projects
I need a help in that please