2012-02-12 1 views
0

J'ai les en-têtes de table, maintenant je sais pourquoi cela se produit (parce que l'écho d'en-tête de table est appelé pour chaque rangée) mais je ne peux pas voir comment le réparer.En-tête de table répétant dans table de données xml

<?php 
$url = "http://elcu.herobo.com/testarea/include/cd_catalog.xml"; 
$xml = simplexml_load_file($url); 

foreach($xml->CD as $cd){ 
    echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead><tr> <th>Title</th> <th>Artist</th> <th>Company</th><th>Price</th></thead><tbody>"; 
    echo "<td width='25%'> ".$cd->TITLE."</td>"; 
    echo "<td width='25%'> ".$cd->ARTIST."</td>"; 
    echo "<td width='25%'> ".$cd->COMPANY."</td>"; 
    echo "<td width='25%'> ".$cd->PRICE."</td>"; 
    echo "</tbody></table>"; 
} 
?> 

Répondre

0

Vous voulez dire:

<?php 
$url = "http://elcu.herobo.com/testarea/include/cd_catalog.xml"; 

$xml = simplexml_load_file($url); 

echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'>\n"; 
echo "<thead><tr> <th>Title</th> <th>Artist</th> <th>Company</th><th>Price</th></thead>"; 
echo "<tbody>"; 

foreach($xml->CD as $cd){ 
    echo "<tr>"; 
    echo "<td width='25%'> ".$cd->TITLE."</td>"; 
    echo "<td width='25%'> ".$cd->ARTIST."</td>"; 
    echo "<td width='25%'> ".$cd->COMPANY."</td>"; 
    echo "<td width='25%'> ".$cd->PRICE."</td>"; 
    echo "</tr>"; 
} 
echo "</tbody>"; 
echo "</table>"; 

?> 

Notez que vous avez appelé table dans votre boucle foreach, et vous n'avez pas non plus spécifié le début et la fin de la ligne avec tr

0

Je pense que la table viendra avant que la boucle foreach afin que chaque enregistrement va créer une ligne plutôt que d'une table

echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead><tr> <th>Title</th> <th>Artist</th> <th>Company</th><th>Price</th></thead><tbody>"; 

foreach($xml->CD as $cd) 

    { 




    echo "<td width='25%'> ".$cd->TITLE."</td>"; 

    echo "<td width='25%'> ".$cd->ARTIST."</td>"; 

    echo "<td width='25%'> ".$cd->COMPANY."</td>"; 

    echo "<td width='25%'> ".$cd->PRICE."</td>"; 


    } 

echo "</tbody></table>"; 
+0

j'ai essayé cela et il casse la table et appelle toutes les données comme une ligne de texte – zhaobaloth

+1

Essayez ma solution - celui-ci est manquant '' et '' .... – MrJ

+0

je ne l'ai pas vu désolé –

Questions connexes