多个表回声未显示在页面中

时间:2013-11-23 15:09:01

标签: php mysql sql

以上代码旨在显示存储在sql表中的信息。一切都对应于表格中的标题和正确的顺序。但它所来自的页面只显示前两列,而不是其他列。一切看起来好像是为了我。我的陈述是错的?

<?php
    $con=mysqli_connect("xxx","y","y","yyyy");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $result = mysqli_query($con,"SELECT * FROM tripdata ");

    while($row = mysqli_fetch_array($result))
      {
      echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode']; 
      echo "<br>";
      }

    mysqli_close($con);
    ?> 

2 个答案:

答案 0 :(得分:1)

也许你可以尝试使用assoc

while($row = mysqli_fetch_assoc($result))
  {
  echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode']; 
  echo "<br>";
  }

我通常使用这个并没有问题

assoc是基于字段名称的索引名称 但是数组基于数字(0,1,2,3)

答案 1 :(得分:0)

奇怪。请尝试循环:

do {    
  echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode']; 
  echo "<br>";

} while($row = mysqli_fetch_array($result));