TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How to stop table header from repeating (http://www.talkphp.com/absolute-beginners/4038-how-stop-table-header-repeating.html)

commonmind 03-13-2009 03:20 PM

How to stop table header from repeating
 
I'm trying to figure out how to stop some table headers from repeating.

PHP Code:

$xml = new SimpleXMLElement($rosterxml); 

foreach (
$xml->guildInfo->guild->members->children() as $char) {
    
    echo 
'
        <table><thead>
        
        <th>Name</th>
        <th>Race</th>
        <th>Class</th>
        <th>Level</th>
        <th>Rank</th>
        <th>Achievements</th>
        
        </thead>
        
        
        
        <tr>  
         <td class="roster">' 
$char['name'] . '</td> 
         <td class="roster">' 
$char['race'] . '</td>
         <td class="roster">' 
$char['class'] . '</td>
         <td class="roster">' 
$char['level'] . '</td>
         <td class="roster">' 
$char['rank'] . '</td>
         <td class="roster">' 
$char['achPoints'] . '</td>
         
      </tr> </table> '
;



Using the above code (I just took a guess as to how to setup the headers, obviously I was wrong), the header repeats along each row.

tony 03-13-2009 04:29 PM

I think it's because you put the header inside the loop. try putting the headers before the loop.

PHP Code:

$xml = new SimpleXMLElement($rosterxml); 
echo 
'<table><thead>
        <th>Name</th>
        <th>Race</th>
        <th>Class</th>
        <th>Level</th>
        <th>Rank</th>
        <th>Achievements</th>
        
        </thead>'
;
foreach (
$xml->guildInfo->guild->members->children() as $char) {
    
    echo 
'<tr>  
         <td class="roster">' 
$char['name'] . '</td> 
         <td class="roster">' 
$char['race'] . '</td>
         <td class="roster">' 
$char['class'] . '</td>
         <td class="roster">' 
$char['level'] . '</td>
         <td class="roster">' 
$char['rank'] . '</td>
         <td class="roster">' 
$char['achPoints'] . '</td>
         
      </tr> '
;

}
echo 
'</table>'


commonmind 03-13-2009 04:41 PM

Thanks Tony, worked perfectly :)

tony 03-13-2009 08:11 PM

No problem, glad I could help


All times are GMT. The time now is 04:51 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0