我正在開發一個應用程序 - 一種微型生物指標。在這個應用程序中,管理員將創建一個特定的用戶併爲他創建其他用戶。主要用戶創建的用戶將是爲人員創建註冊的用戶。我有兩個表,一個用於管理員用戶,另一個用於用戶註冊。我想要的是通過此子用戶已添加到users表中的用戶數來獲取管理員下的所有子用戶。如何從mysql數據庫中選擇主用戶及其子用戶
這裏的源代碼。它沒有給我我需要的東西。
<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>
爲了清楚起見,這裏有兩個表: 管理員用戶表
用戶表Img.2
到目前爲止您嘗試過什麼? –
@AhmedGinani,我發佈了源代碼。 –
另外,在執行新的查詢之前,您應該「清理」stmt:oci_free_statement($ stmt); –