dsbpaqt61965 2019-05-22 17:59
浏览 70
已采纳

PHP通过单击视图按钮查看单个记录中的数据

I have two pages students_list.php and students_profile.php

On students_list.php i have a table showing all records of all students and the VIEW button which when clicked it should open the students_profile.php page and get all the data from the single record selected based on the std_id

UPDATE: So now i get the id http://localhost/sms/student_profiles.php?std_id=3 when i click on the VIEW button but i am still not retrieving the data from this record selected

This is the code for students_list.php

<?php
require_once 'include/database/connect.php';

try {
    $pdo = new PDO("mysql:host=$host_db;dbname=$name_db", $user_db, $pass_db);                                 
    $sql = 'SELECT * FROM students';
    $q = $pdo->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
    die("Could not connect to the database $name_db :" . $e->getMessage());
    }
?>
<table id="data-table-default" class="table">
    <thead>
    <tr>
    <th width="1%">#</th>
    <th width="1%" data-orderable="false"></th>
    <th>Name & Surname</th>
    <th>Gender</th>
    <th>Faculty</th>
    <th>Semester</th>
    <th>Mobile</th>
    <th></th>
    </tr>
</thead>

<tbody>
    <?php while ($row = $q->fetch()): ?>
    <tr class="odd gradeX">
    <td width="1%" class="f-s-600 text-inverse"><?php echo ($row['std_id']) ?></td>
    <td width="1%" class="with-img"><?php echo ($row['std_status']) ?></td>
    <td><?php echo ($row['std_name']) ?></td>
    <td><?php echo ($row['std_gender']) ?></td>
    <td><?php echo ($row['std_faculty']) ?></td>
    <td><?php echo ($row['std_semester']) ?></td>
    <td><?php echo ($row['std_mobile']) ?></td>
    <td align="right">
    <a href="student_profiles.php?std_id=<?php echo $row['std_id']; ?>" class="btn btn-warning btn-xs"><i class="fas fa-eye"></i> View</a>
    </td>
    </tr>
    <?php endwhile; ?>
    </tbody>
</table>

and below this is the student_profile.php

<?php
require_once('include/database/sharepoint.php');
if(isset($_GET) & !empty($_GET)){
    $std_id = $_GET['std_id'];
    $sql = "SELECT * FROM `students` WHERE std_id=$std_id";
    $res = mysqli_query($connection, $sql);
}
?>

<h4><?php echo ($row['std_name']) ?></h4>

<div class="d-flex">
    <div class="pr-4"><strong>NATIONAL#</strong> <?php echo ($row['std_number']) ?></div>
    <div class="pr-4"><strong>DOB</strong> <?php echo ($row['std_dob']) ?></div>
    <div class="pr-4"><strong>GENDER</strong> <?php echo ($row['std_gender']) ?></div>
    <div class="pr-4"><strong>MOBILE</strong> <?php echo ($row['std_mobile']) ?></div>
</div>
<div class="pt-1 font-weight-bold">Master's Degree (MBA)</div>
<div>STD# <strong><?php echo ($row['std_id']) ?></strong></div>
<div><a href="#" target="new">email@example.com</a></div>
  • 写回答

1条回答 默认 最新

  • dsndm82062 2019-05-23 15:09
    关注

    You don't fecth the data from the query. So $row will never contain the array you expect:

    $row = mysqli_fetch_assoc($res); //this will populate $row
    

    in your code:

    <?php
    require_once('include/database/sharepoint.php');
    if(isset($_GET) & !empty($_GET)){
        $std_id = $_GET['std_id'];
        $sql = "SELECT * FROM `students` WHERE std_id=$std_id";
        $res = mysqli_query($connection, $sql);
        $row = mysqli_fetch_assoc($res);
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题