获取单个父ID和所有子ID

时间:2017-08-21 12:23:43

标签: php mysql

我希望在同一级别获取用户创建者ID(例如:父ID)及其所有子ID。但是只有fetch上级和下级id。我的问题似乎是在SQL查询中。

<?php  
    include('config.php');
    $user_level_up=$_SESSION["level"];
    $user_level_down=$_SESSION["level"];
    $user_id = $_SESSION['id'];
    $user_level_up+=1;
    $user_level_down-=1;
    $sql = "select * from users where  level = '$user_level_up' OR 
            level='$user_level_down'"; 
    $result = mysqli_query($conn , "$sql");
    if(mysqli_num_rows($result) > 0 )
    {
    while( $row=mysqli_fetch_array($result)) 
    {  
    // preparing an array

    ?>
    <option value="<?php echo $row['id']; ?>"><?php echo $row["username"]. "
    (".$row["email"].")"."(".$row["id"]. ")" . "(" . $row['level'] . ")" . "(" . 
    $row['create_user_id'] . ")" ; ?></option>
   <?php  }
   } ?>

1 个答案:

答案 0 :(得分:1)

像这样使用您的查询

$sql = "select * from users where  level = '".$user_level_up."' OR 
        level='".$user_level_down."'";