我目前正在研究一个搜索系统,我希望显示所有具有2个列名称的行,问题是,当我在数据库中有2个时,我的while循环只显示1行。我一直在努力工作几个小时,但我无法得到它。我得到的唯一输出是最后价格。
<?php
include_once("inc/head.php");
include_once("inc/db.php");
$leave = $_POST['departure'];
$come = $_POST['destination'];
$leavedate = $_POST['leavedate'];
$comedate = $_POST['comedate'];
$sql = "select * from flights where departure = '$leave' and destination ='$come'";
$result = $db->query($sql);
$row = $result->fetchObject();
$price = $row->price;
$mostflights = $row->departure;
$mostcomings = $row->destination;
?>
<div>
<ul class="flights">
<?php
while($row = $result->fetchObject())
$price = $row->price;
$mostflights = $row->departure;
$mostcomings = $row->destination;
{ ?>
<li>
<h3><?php echo $mostflights; ?></h3>
<h2><?php echo $mostcomings; ?></h2>
<h2><?php echo $price; ?></h2>
</li>
<?php
}
?>
</ul>
</div>
答案 0 :(得分:1)
在第10行删除此块
$row = $result->fetchObject();
$price = $row->price;
$mostflights = $row->departure;
$mostcomings = $row->destination;