Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

php - How to list multiple table results in an unordered list

I am trying to list existing user profiles from the database but only one result is shown whereas there are multiple records.

  $SQL_Users = "SELECT DISTINCT first_party_code FROM t_planning";
    
    $RESULT = mysqli_query( $conn, $SQL_Users);

    while($row_Users = mysqli_fetch_array($RESULT)) 
    {
        $data0 = "<ul class='list-unstyled users-list'>";

        $SQL_User_Info = "SELECT title, first_name, middle_name, last_name, profile_image_name FROM t_employees WHERE employee_code = '" .  $row_Users["first_party_code"] . "'";
        $RESULT_Users = mysqli_query( $conn, $SQL_User_Info);

        while($Users = mysqli_fetch_array($RESULT_Users)) 
        {
        $data0.= "<li data-toggle='tooltip' data-popup='tooltip-custom' data-placement='bottom' title='" . $Users["title"] . " " . $Users["first_name"] . " " . $Users["middle_name"] . " " . $Users["last_name"] . "' class='avatar pull-up'>
                
        <img class='media-object rounded-circle' src='../uploads/users_profile_images/" . $Users["profile_image_name"] . "' alt='Avatar' height='30' width='30'>
            
        </li>";
    }
        echo $data0.="</ul>";

        mysqli_close($conn);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found where the problem was. I was closing the mysqli_close($conn) prematurely.

$SQL_Users = "SELECT DISTINCT first_party_code FROM t_planning";
    
    $RESULT = mysqli_query( $conn, $SQL_Users);

    while($row_Users = mysqli_fetch_array($RESULT)) 
    {
        $data0 = "<ul class='list-unstyled users-list'>";

        $SQL_User_Info = "SELECT title, first_name, middle_name, last_name, profile_image_name FROM t_employees WHERE employee_code = '" .  $row_Users['first_party_code'] . "'";
        $RESULT_Users = mysqli_query( $conn, $SQL_User_Info);

        while($Users = mysqli_fetch_array($RESULT_Users)) 
        {
        $data0.= "<li data-toggle='tooltip' data-popup='tooltip-custom' data-placement='bottom' title='" . $Users["title"] . " " . $Users["first_name"] . " " . $Users["middle_name"] . " " . $Users["last_name"] . "' class='avatar pull-up'>
                
        <img class='media-object rounded-circle' src='../uploads/users_profile_images/" . $Users["profile_image_name"] . "' alt='Avatar' height='30' width='30'>
            
        </li>";
        }
        echo $data0.="</ul>";
                                       
    }   

    mysqli_close($conn);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...