I couldn't loop through score record. It keeps replacing the score of new user but does not display the record of previous user.
Here is the code. users.php
public function show_per($matricnum)
{
$query=$this->conn->query("select * from percentage where matricnum='$matricnum'");
$row=$query->fetch_array(MYSQLI_ASSOC);
if($query->num_rows>0)
{
$this->data[]=$row;
}
return $this->data;
}
viewre.php
<div class="container">
<center><h2>Student Result Record</h2>
<?php
$i=1;
foreach($result->data as $view)
{?>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Matric Number</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $view['id']; ?></td>
<td><?php echo $view['matricnum'];?></td>
<td><?php echo $view['per'];?></td>
</tr>
</tbody>
<?php $i++; }?>
</table>
</div>
mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe SQL injection bug. NEVER put$_POST,$_GETor any user data directly into a query, it can be very harmful if someone seeks to exploit your mistake.