【发布时间】:2021-05-01 06:01:00
【问题描述】:
这是显示数据库中所有数据的主表,当我单击打印时,它应该只打印该行但它不显示我得到“未定义的变量:行”,我开始认为这与此有关这里是表格的代码:
<div class="container" >
<div class="well" ">
<span class="pull-right"><a data-toggle="modal" data-target="#myModal" href="#myModal" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Enroll Pupil</a></span>
<div>
</div>
<table class="table table-striped table-bordered table-hover" >
<thead>
<th >Moble Number</th>
<th >First Name</th>
<th>Last Name</th>
<th>Section</th>
<th>Grade</th>
<th>Action</th>
</thead>
<tbody>
<?php
include('conn.php');
$query=mysqli_query($conn,"select * from `tbl_students`");
while($row=mysqli_fetch_array($query)){
?>
<tr s>
<td><?php echo $row['LRN']; ?></td>
<td><?php echo $row['FirstName']; ?></td>
<td><?php echo $row['LastName']; ?></td>
<td><?php echo $row['Section']; ?></td>
<td><?php echo $row['GradeLevel']; ?></td>
<td >
<a href="#editstudent<?php echo $row['LRN']; ?>" data-toggle="modal" class="btn btn-warning"><span class="glyphicon glyphicon-edit"></span> Edit</a> | |
<a href="#delstudent<?php echo $row['LRN']; ?>" data-toggle="modal" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Delete</a> | |
<a href="#addmoto<?php echo $row['LRN']; ?>" data-toggle="modal" data-target="#addmoto" class="btn btn-info"><span class="glyphicon glyphicon-edit"></span> Add Subject</a> | |
<a class="btn btn-success" onclick="window.open('IndivPrintTableStudent.php').print();">Print</a>
<?php include('buttonstudent.php'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
<?php include"includes/config.php" ?>
<link rel="stylesheet" type="text/css" href="Print.css" media="print"></link>
<div class="container" >
<table>
<thead>
<th style="border: 3px solid #2F323A; text-align: center; padding-bottom: 8px;">Moble Number</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 14%;">First Name</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 14%;">Last Name</th>
<th style="border: 3px solid #2F323A; text-align: center; padding-bottom: 9px;">Section</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 10%;">Grade</th>
</thead>
<tbody>
<?php
$query=mysqli_query($con,"SELECT * FROM tbl_students WHERE LRN='".$row['LRN']."'");
while($row=mysqli_fetch_array($query)){
?>
<tr style="background-color: #f0f8ff; border: 3px solid #2F323A;">
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['LRN']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['FirstName']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['LastName']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['Section']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['GradeLevel']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
如何以单独的方式获取单个数据?我得到的错误是“未定义的变量:行”,您可以在查询中看到。我不知道为什么它说我只制作表格只是为了看看我是否可以从单个学生那里获得实际数据。我希望我的问题可以理解。
【问题讨论】:
-
我可以从您的代码中看到变量 $row 已定义
-
我可以看看你的数据库表吗?
-
废话我忘了说这段代码是打印的输出。
-
@NazmulHossainPappu 是的,我会编辑我的帖子。
-
第一个表中会有类似
onclick="window.open('IndivPrintTableStudent.php?LRN=<?PHP echo $row["LRN"]; ?>').print();的内容。然后第二个脚本将使用$_GET["LRN"]从 URL 中检索该值并在 sql 查询中使用它。 (但要小心 SQL 注入,学习如何使用参数和准备好的语句来保护您的数据库)