简体   繁体   中英

Looping SQL Results into a table

I'm just struggling to have my SQL output loop within a table. Currently, it displays one result within the table and the remaining out of it. If I put the entire table within the while loop, it creates a new table for each row... Please help!

Code below

    if (mysqli_num_rows($result) > 0)
    {
        echo
        "<table class='xsmall' align='center'>
        <tr><th>Costume ID</th>
        <th>Description</th>
        <th>Size</th></tr>";

        while($row = mysqli_fetch_array($result))
        {
        //-----------------Echoing Results-----------------------//
        echo 
        "<tr><td>".$row['Fname']."</td>
        <td>".$row['Sname']."</td>
        <td>".$row['AvgSpend']."</td></tr>
        </table><br>";
        }
    }
echo "<table>";
while($row = mysqli_fetch_array($result)) {
echo "
<tr>
<td>'".$row['Fname']."'</td>
<td>'".$row['Sname']."'</td>
<td>'".$row['AvgSpend']."'</td>
</tr>";
}
echo "</table>";

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