2016-12-15 56 views
-1

我目前正在一个搜索系统,我想显示所有有2列名称的行,问题是,我的while循环只显示1行,当我有2人在数据库中。我一直在努力工作几个小时,但我无法得到它。我得到的唯一结果是最后一个价格。虽然循环显示只有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

的结果是什么,当你在你的DBMS尝试手动查询此块? – Beginner

+0

从出发='$ leave'和destination ='$ come'的航班选择*如果我用我从邮局获得的名称替换变量我得到一个成功的查询 –

+0

为什么你使用'fetchObject()'两次? –

回答

1

删除在10日线

$row = $result->fetchObject(); 
$price = $row->price; 
$mostflights = $row->departure; 
$mostcomings = $row->destination; 
+0

这样做给了相同的结果,我仍然只能看到最后一行的价格,如果我删除价格变量,我可以看到最flyf值等。 –

+0

请在while循环之后将第一个打开的curl移动到'',像这样'while($ row = $ result-> fetchObject()){' –

+0

这样做,我也只是注意到我做错了什么。 –