in my coding i have two foreach statement. But the way i wrothe the code it is wrong. could anyone please tell me what shoud be the correct format to write multiple foreach statement.
the $people statement for id, passport_is, blood_group,blood_bag. The $donor statement for donation_date.
thanks in advance.
here is my code
<?php
$db = new PDO('mysql:dbname=mypro_bms;host=localhost', 'root', '');
if (isset($_GET['q'])) {
$q = $_GET['q'];
$statement = $db->prepare("select * from donate where passport_IC like :passport_IC");
$statement->execute([
':passport_IC' => '%' . $q .'%'
]);
} else {
$statement = $db->prepare('select * from donate');
$statement->execute();
}
$people = $statement->fetchAll(PDO::FETCH_OBJ);
?>
<?php
$statement = $db->prepare('select donation_date from tbl_user');
$statement->execute();
$donor = $statement->fetchAll(PDO::FETCH_OBJ);
?>
<table class="table table-bordered">
<tr>
<th>id</th>
<th>Passport/IC</th>
<th>Blood Group</th>
<th>Blood Bag Type</th>
<?php foreach($peoples as $people){
foreach($donors as $donor){ ?>
<tr>
<td><center><b><font color="black"><?php echo $people->id; ?></font></b></center></td>
<td><center><b><font color="black"><?php echo $people->passport_is; ?></font></b></center></td>
<td><center><b><font color="black"><?php echo $people->blood_group; ?></font></b></center></td>
<td><center><b><font color="black"><?php echo $people->blood_bag; ?></font></b></center></td>
<td><center><b><font color="black"><?php echo $donor->donation_date; ?></font></b></center></td>
<td><a href="delete.php?id=<?php echo $people->id; ?>">Delete</a></td>
</tr>
<?php}
}?>
</tr>
</table>