php - 如何在 PHP 中使用 Select 选项从数据库中获取数据?
问题描述
我会使用 select 选项从数据库中获取数据,但没有任何输出显示...任何人都可以找到问题 问题是什么,无论是我的代码还是我们采用了错误的技术?这是我下面的代码`
<div class="heading" style="margin-bottom:10px; float:left; color:black;">Select Records</div>
<div style="float:right; color:black;">
<form >
<select name="session" >
<option value='Null'><b>Select Session</b></option>
<?php
$status_on = 'no';
$query1 = "select * from sessions where
status='$status_on'";
$run = mysqli_query($con,$query1);
while($row=mysqli_fetch_array($run)){
$id = $row['session_id'];
$p_id = $row['program_id'];
$session_name = $row['session_name'];
echo "
<option value='$id'><b>$session_name</b></option>";
}
?>
</select>
<input type="submit" value="go" />
<div style="color:red;">
<?php
if(isset($_GET['go'])){
$session = $_GET['session'];
$sql = "select * from students where session_id like'%$session%'";
//$sql = "select * from students where session_id='$session%'";
// also tried
$run = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($run)){
$s_name = $row['s_name'];
?>
<table>
<tr>
<td><?php echo $s_name;?></td>
</tr>
<?php }?>
<?php }?>
</table>
</div>
</form>
</div>
<?php include("footer.php");?>
解决方案
对输出表进行了更正:
<?php
if(isset($_GET['go'])){
$session = $_GET['session'];
$sql = "select * from students where session_id like'%$session%'";
//$sql = "select * from students where session_id='$session%'";
// also tried
$run = mysqli_query($con,$sql);
?>
<table>
<?
while($row = mysqli_fetch_array($run)){
$s_name = $row['s_name'];
?>
<tr>
<td><?php echo $s_name;?></td>
</tr>
<?php }?>
</table>
<?php }?>
推荐阅读
- c# - C#:FileStream.ReadByte() 是多线程友好函数吗?
- java - 为什么我的 Eclipse JRE 库 JDK 13 未绑定?
- azure - 是否可以将更改源处理器主机作为 Azure Web 作业运行?
- c++ - Stack Smashing 在纸牌游戏中检测到 C++
- .net-core - 使用 EF 保存实体并使用 SignalR 以相同的方法向客户端发送消息
- node.js - “响应”类型上不存在属性“本地人”
- c - 没有 SIMD 的向量化相等测试
- pytorch - 如何在 PyTorch 中保存模型架构?
- php - Laravel 6关系在DB中具有不同表名的一对多关系
- react-native - 循环并获取组件/屏幕中的所有 TextInput 值