我有两页students_list.php 和students_profile.php在students_list.php 上,我有一个表格显示所有学生的所有记录和VIEW 按钮,单击该按钮时应打开students_profile.php 页面并从基于std_id 选择的单个记录中获取所有数据更新:所以现在当我点击 VIEW 按钮时我得到了 id http://localhost/sms/student_profiles.php?std_id=3但我仍然没有从这个选择的记录中检索数据这是students_list.php的代码<?phprequire_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<?phprequire_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);}
1 回答
潇潇雨雨
TA贡献1833条经验 获得超4个赞
您不会从查询中获取数据。所以 $row 永远不会包含你期望的数组:
$row = mysqli_fetch_assoc($res); //this will populate $row
在您的代码中:
<?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);
}
?>
- 1 回答
- 0 关注
- 251 浏览
添加回答
举报
0/150
提交
取消