首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP通过单击查看按钮查看单个记录中的数据

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

Stack Overflow用户
提问于 2019-05-23 01:59:48
回答 1查看 534关注 0票数 0

我有两个页面students_list.php和students_profile.php

在students_list.php上,我有一个显示所有学生的所有记录的表和一个查看按钮,当单击该按钮时,它将打开students_profile.php页面,并从基于std_id选择的单个记录中获取所有数据

更新:现在,当我单击http://localhost/sms/student_profiles.php?std_id=3按钮时,我得到了id视图,但是我仍然没有从所选的记录中检索数据

这是students_list.php的代码

代码语言:javascript
复制
<?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>

下面是student_profile.php

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 23:09:43

您不需要从查询中提取数据。因此,$row永远不会包含您期望的数组:

代码语言:javascript
复制
$row = mysqli_fetch_assoc($res); //this will populate $row

在你的代码中:

代码语言:javascript
复制
<?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);
}
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56262519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档