显示数据库中的每个数据

时间:2016-12-28 04:31:08

标签: php html

enter image description here

我已经显示了数据库中的名称列表,但问题是我不知道如何显示每个用户的信息,一旦我点击列表中的某个用户,她/他的信息就会出现。

HTML

<div class="member_list">
    <div class="list-unstyled">
        <?php require_once "../function/admin_function.php"; ?>
    </div>
</div>

<div class="information" id="table_information">
    <table class="table_information">
        <tr>
            <th colspan="4">Information</th>
        </tr>
        <tr>
            <th>lastname</th>
            <th>address</th>
            <th>contact</th>
        </tr>
        <tr>
            <td>
                <?php include "../function/information_function.php"; ?>
            </td>
        </tr>
    </table>
</div>

information_function - php

<?php 
include "../connection/connection.php";

$sql = "SELECT * FROM registration";
$result = mysqli_query($dbconn, $sql);

while ($row = mysqli_fetch_array ($result)){
    echo "<tr>";
    echo "<td>" . $row['lname'] . "</td>";
    echo "<td>" . $row['address'] . "</td>";
    echo "<td>" . $row['contact'] . "</td>";
    echo "</tr>";
}
?>

用户列表 - php

<?php 
include "../connection/connection.php";

$sql = "SELECT * FROM registration";
$result = mysqli_query ($dbconn, $sql);

while($row = mysqli_fetch_array ($result)) {
    echo "<ul class='table_php'>";
    echo "<li>";
    echo "<a href='#table_information' class='friends_link'>";                  
    echo "<span class='chat-img pull-left'>";
    echo "<img src='user.png' class='img-circle'>"; 
    echo "</span>" . $row['lname'] . "</a>";
    echo "</li>";           
    echo "</ul>";
}
?>

1 个答案:

答案 0 :(得分:0)

将代码放在函数中,然后在include语句之后调用该函数。

// // information_function

<?php 
 include "../connection/connection.php";
function get_information(){
 $sql = "SELECT * FROM registration";
 $result = mysqli_query($dbconn, $sql);

  while ($row = mysqli_fetch_array ($result)){


  echo "<tr>";
  echo "<td>" . $row['lname'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['contact'] . "</td>";
  echo "</tr>";

  }
}
  ?>

// // HTML

<div class="member_list">
  <div class="list-unstyled">
    <?php require_once "../function/admin_function.php"; ?>
  </div>
 </div>

<div class="information" id="table_information">
  <table class="table_information">
   <tr>
    <th colspan="4">Information</th>
   </tr>
   <tr>
    <th>lastname</th>
    <th>address</th>
    <th>contact</th>
   </tr>


     <?php include "../function/information_function.php"; ?>
 <?php get_information(); ?>

  </table>
 </div>