I am developing an application - a kind of mini bio metrics. in this application admin will create a particular user and give him an access to create other users. The users created by the main user will be the ones creating registration for people. I have two tables, one for admin users, the other for users registration. What I want is to fetch all sub users under admin with the number of users this sub users have added to the users table.
here the source code. It it not giving me what I needed.
<div class="content-loader">
<?php
if($pri == 'user' && $utype == 'super_admin'){
?>
<table cellspacing="0" width="100%" id="example" class="table display table-striped table-hover table-responsive">
<thead>
<tr>
<th>#ID</th>
<th>Name</th>
<th>username</th>
<th>no of people registered</th>
<th>Date Added</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i =1;
$stmt = $db_con->prepare("SELECT * FROM users where adder in (select uid from admin_user where adder = '$id')" );
$stmt->execute();
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$ad = $row['adder'];
$stmt = $db_con->prepare("SELECT * FROM admin_user where uid = '$ad' " );
$stmt->execute();
while($rows=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr class="delete_user<?php echo $rows['uid']; ?>">
<td><?php echo $i; $i++;?></td>
<td><?php echo $rows['name']; ?> </td>
<td><?php echo $rows['username'];?></td>
<td><?php //echo $rows['tot'];?></td>
<td><?php echo $rows['date_added'];?> (<?php echo timeAgo($rows['time_added']) ?>)</td>
<td class="td-actions text-right">
<!--<a id="<?php echo $rows['uid']; ?>" class="edit-link btn btn-primary btn-simple btn-xs" rel="tooltip" href="#" title="Edit User"><i class="material-icons">edit</i></a>-->
<a id="<?php echo $rows['uid']; ?>" class="btn btn-danger btn-user">
<span class="glyphicon glyphicon-trash"></span>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}else{
?>
<div class="panel-warning" style="padding:7px; text-align:center; font-size:18px;">This page is for the administrator!</div>
<?php
}
?>
</div>
</div>
For clarification, here are the two tables: Admin users table
Users table added by both the admin and his sub users
Users table Img.2