dongsou8980 2016-01-10 06:59
浏览 94
已采纳

使用php mysqli显示人员列表中的详细信息

I am trying to display a list of persons. On clicking the list , more details on the person must be shown.

members.php: -a page to list all members

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <h1>Our members are</h1>
    <?php 
    include 'config.php';
    session_start();
    $sql = "SELECT name from users";
    $result = $conn->query($sql);
    echo '<table>';
    if($result->num_rows > 0)
    {
        while($row = $result->fetch_assoc())   
                        {
                             echo '<tr>';
                             $_SESSION['selection'] = $row['name'];
                             echo '<td><a href = "view.php">'.$row['name'].'</a></td>'; 
                             echo '</tr>';
                        }
    }
    echo '</table>';
    $conn->close();
    ?>
</body>

view.php -the page to show more details:

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <?php
    include 'config.php';
    session_start();
    $pkey = $_SESSION['selection'];
    $new = "SELECT * FROM users where name = '$pkey'";
    $display = $conn->query($new);
    $result = $display->fetch_assoc();
    echo 'Name:'.$result['name'];
    echo 'Rollno:'.$result['rool_no'];
    echo 'Description:'.$result['description'];

    $conn->close();
    ?>
</body>

on using session , always the details of last person in the list is shown. How to display the corresonding details??

  • 写回答

1条回答 默认 最新

  • dqh19413 2016-01-10 07:18
    关注

    finally you are saving last name in the session variable $_SESSION['selection'] = $row['name']; so you getting the last name .while loop end with last name and you saving it in session.you are not using session as array know that.

    my advice is not use session. session is not required here.

    while($row = $result->fetch_assoc())   
                            {
                                 echo '<tr>';
                                 $_SESSION['selection'] = $row['name'];
                                 echo '<td><a href = "view.php">'.$row['name'].'</a></td>'; 
                                 echo '</tr>';
    
              }
    

    change these lines in members.php

     while($row = $result->fetch_assoc())   
                        {
                             echo '<tr>';
                             echo '<td><a href = "view.php?name=$row['name']">'.$row['name'].'</a></td>'; 
                             echo '</tr>';
                        }
    

    and change these line in view.php

    <body>
    <?php
    include 'config.php';
    session_start();
    $pkey = $_REQUEST['name'];//change this line alone
    $new = "SELECT * FROM users where name = '$pkey'";
    $display = $conn->query($new);
    $result = $display->fetch_assoc();
    echo 'Name:'.$result['name'];
    echo 'Rollno:'.$result['rool_no'];
    echo 'Description:'.$result['description'];
    
    $conn->close();
    ?>
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?