标题排在所有行中

时间:2016-11-01 09:43:43

标签: php

标题出现在第一行中需要的所有行

在我出错的地方需要帮助

谢谢

下面是代码

<?php 
$connection = mysql_connect('localhost', 'aria2', 'osvOSUxlY6wYLZzC'); //The      Blank string is the password
 mysql_select_db('torres');
 $query = "SELECT * FROM reports"; //You don't need a ; like you do in SQL
 $result = mysql_query($query) or die(mysql_error());;
   echo "<table>"; // start a table tag in the HTML
  while($row = mysql_fetch_array($result)){   //Creates a loop to loop    through results
  echo "<table><tr><th>CSQ_Name</th>
  <th>CSQ_ID</th>.......
$row..............  
   //$row['index'] the index here is a field name
             }
          echo "</table>"; //Close the table in HTML
   mysql_close(); //Make sure to close out the database connection

1 个答案:

答案 0 :(得分:1)

您只需要将标题部分移出循环:

echo '<table><tr><th>CSQ_Name</th><th>CSQ_ID</th></tr>';   // start a table tag in the HTML
while ($row = mysql_fetch_array($result)) {    //Creates a loop to loop   
  echo '<tr>';
  // output data here
  echo '<td>...</td><td>...</td>';
  echo '</tr>';
}
echo "</table>"; //Close the table in HTML