简体   繁体   中英

SQL query create table with headings

Currently I am creating a HTML table with data from one of my SQL tables. However I want to put headings for each column (note: I don't want to use the database headings). How can I do this? Below is my current code without headings:

<?php
$searchResults = mysql_query("SELECT customerRefId, suburb, postcode, state FROM customer_seeking");
$num_rows = mysql_num_rows($searchResults);
?>
<table border="1">
<?php
while($row=mysql_fetch_array($searchResults))
{
echo"<tr><td>$row[customerRefId]</td><td>$row[suburb]</td><td>$row[postcode]</td><td>$row[state]</td></tr>";
}
?>
</table>

Hey You can use the following code for header:::

<table border="1">
    <tr><th>customer Ref Id</th><th>suburb</th><th>postcode</th><th>state</th></tr>
    <?php
    while($row=mysql_fetch_array($searchResults))
    {
    echo"<tr><td>$row[customerRefId]</td><td>$row[suburb]</td><td>$row[postcode]</td><td>$row[state]</td></tr>";
    }
    ?>
    </table>

Just added under table

<table border="1">
<th>Test</th>
<th>Test2</th>

while循环之前输出标题行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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