简体   繁体   English

在PHP上没有用于打印表的MYSQL连接查询的输出

[英]No ouput for MYSQL join query for printing table on PHP

require_once 'dbconnect.php';
if(isset($_POST['search1'])){
  if($_POST['search1']=="tour"){
    $query2 = $DBcon->query("select * from tourinfo inner join flight on tourinfo.fid = flight.fid inner join hotel on tourinfo.hid = hotel.hid");
    echo "<table>";
              echo "successful";
    while($row=$query2->fetch_array()){
      echo "
        <tr>
          <th>Tour ID</th>
          <th>Destination</th>
          <th>Tour Duration(Day)</th>
          <th>Price</th>
          <th>Flight ID</th>
          <th>Flight Duration(hours)</th>
          <th>Depart Time</th>
          <th>Airport</th>
          <th>Flight No</th>
          <th>Hotel ID</th>
          <th>Hotel Name</th>
        </tr>
        <tr>
          <td>".$row[0]."</td>
          <td>".$row[1]."</td>
          <td>".$row[2]."</td>
          <td>".$row[3]."hours</td>
          <td>".$row[4]."</td>
          <td>".$row[8]."</td>
          <td>".$row[9]."</td>
          <td>".$row[10]."</td>
          <td>".$row[11]."</td>
          <td>".$row[13]."</td>
          <td>".$row[14]."</td>
        </tr> 
      ";
    }
  }
}
echo "</table>";

Here is my code for using join operation of MYSQL and printing the column in a table form. 这是我的代码,用于使用MYSQL的联接操作并以表格形式打印列。 However, there is no output displayed no even a cell or anything? 但是,没有输出,甚至没有显示任何单元格或其他内容?

The "successful message" did appear and I have tested the sql statement to be valid (MySQL returns several rows as expected) . 确实出现了“成功消息”,并且我已经测试了sql语句是否有效(MySQL按预期返回了几行) So what is the problem here? 那么这是什么问题呢?

And I don't need all of the data selected from the database so the index of row isn't consecutive. 而且我不需要从数据库中选择所有数据,因此行的索引不是连续的。

Try this, I'm not sure that it will work : 试试这个,我不确定它是否可以工作:

    <?php
    require_once 'dbconnect.php';
    if(isset($_POST['search1'])){
      if($_POST['search1']=="tour"){
        $query2 = "SELECT * FROM tourinfo INNER JOIN flight ON tourinfo.fid = flight.fid INNER JOIN hotel ON tourinfo.hid = hotel.hid";
        echo "<table>";
          echo "successful";
        foreach ($DBcon->query($query2) as $row) {
          echo "
            <tr>
              <th>Tour ID</th>
              <th>Destination</th>
              <th>Tour Duration(Day)</th>
              <th>Price</th>
              <th>Flight ID</th>
              <th>Flight Duration(hours)</th>
              <th>Depart Time</th>
              <th>Airport</th>
              <th>Flight No</th>
              <th>Hotel ID</th>
              <th>Hotel Name</th>
            </tr>
            <tr>
              <td>".$row[0]."</td>
              <td>".$row[1]."</td>
              <td>".$row[2]."</td>
              <td>".$row[3]."hours</td>
              <td>".$row[4]."</td>
              <td>".$row[8]."</td>
              <td>".$row[9]."</td>
              <td>".$row[10]."</td>
              <td>".$row[11]."</td>
              <td>".$row[13]."</td>
              <td>".$row[14]."</td>
            </tr> 
          ";
        }
      }
    }
    echo "</table>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM