在表中显示mysqli_multi_query的结果

时间:2017-03-25 14:53:46

标签: php mysql sql html-table

我试图将两个查询的结果回显到表中。它似乎将结果拆分为单独的行而不是彼此相邻。 spaceid和venueid的值在db中匹配。

这是我的代码:

 <?php
$con=mysqli_connect("host","username","pword","mydb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql = "SELECT venue.venuename FROM venue INNER JOIN space ON space.spaceID=venue.venueID;";
$sql .= "SELECT space.room, space.costoftables FROM space INNER JOIN venue ON space.spaceID=venue.venueID;";
?>
<table class="tablesorter" width="600px" border="1" cellpadding="1" cellspacing="1" id="myTable">
<thead>
<tr>
<th>Venue Name</th>  <th>Room</th> <th>Cost</th>
</tr></thead><tbody>
<?php
// Execute multi query
if (mysqli_multi_query($con,$sql)){
  do{
      // Store first result set
    if ($result=mysqli_store_result($con)) {
      // Fetch one and one row
      while ($row=mysqli_fetch_array($result))
        {
        echo "<tr>";
        echo "<td>".$row['venuename']."</td>";
        echo "<td>".$row['room']."</td>";
        echo "<td>".$row['costoftables']."</td>";
        }
        ?>
        </tr>
        <?php

      }
    }
  while (mysqli_next_result($con));
}

mysqli_close($con);
?>
</tbody>
</table>

结果如下: Results

0 个答案:

没有答案