Jump to content

My Table is repeating titles


imsry

Recommended Posts

The code works but the title is repeated with each new set of data. I want the titles set up at the top and never repeating... No idea what is causing it.

$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT deadchar, level, class, killforumid, realm, date FROM pkdata ORDER BY deadchar DESC";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
    
    
$deadchar = $row['deadchar'];
$level = $row['level'];
$class = $row['class'];
$killforumid = $row['killforumid'];
$realm = $row['realm'];
$date = $row['date'];

$conn->close();

    echo
        "<table><center><tr>
        
            <th>             
            
           <font size=3 color=#070719>Victim</font>
            
                         </th>
            <th>             
            
            <font size=3 color=#070719>Level</font>
            
                         </th>
            <th>             
            
           <font size=3 color=#070719>Class</font>
            
                         </th>
            <th>             
            
           <font size=3 color=#070719>Killer</font>
            
                         </th>
            <th>             
            
           <font size=3 color=#070719>Realm</font>
            
                         </th>
            <th>             
            
            <font size=3 color=#070719>Date</font>
            
                         </th>
            
            </tr></center>";




        echo
            "<tr><center>
            
            <td><center>$deadchar</center></td>
            <td><center>$level</center></td>
            <td><center>$class</center></td>
            <td><center>$killforumid</center></td>            
            <td><center>$realm</center></td>
            <td><center>$date</center></td>           
            
            </tr>";

    echo "</table>";
    
    
    
    
}

?>
Link to comment
Share on other sites

You had everything within the loop, so it showed every time

 

Added some css, you can style it additional

<style type="text/css">
.tg  {color:black;border-collapse:collapse;border-spacing:0;}
.tg td{color:red;font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{color:green;font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
</style>
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT deadchar, level, class, killforumid, realm, date FROM pkdata ORDER BY deadchar DESC";
$result = $conn->query($sql);

echo "
<table class='tg'>
  <tr>
    <th class='tg'>Victim</th>
    <th class='tg'>Level</th>
    <th class='tg'>Class</th>
    <th class='tg'>Killer</th>
    <th class='tg'>Realm</th>
    <th class='tg'>Date</th>
  </tr>";

while($row = $result->fetch_assoc()) {
   
$deadchar = $row['deadchar'];
$level = $row['level'];
$class = $row['class'];
$killforumid = $row['killforumid'];
$realm = $row['realm'];
$date = $row['date'];

echo "
<tr>
    <td class='tg'>$deadchar</td>
    <td class='tg'>$level</td>
    <td class='tg'>$class</td>
    <td class='tg'>$killforumid</td>
    <td class='tg'>$realm</td>
    <td class='tg'>$date</td>
</tr>";

}

echo '</table>';
$conn->close();
?>
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.