2016-02-11 30 views
1

对于某人来说,这可能是无稽之谈,但是我也不能在某些日子里占上风。 我有这个代码,我从查询中创建一个表我想列标题被重复每一行。对于表中的每一行,HTML表格标题会继续重复

$contenuto="<table align = center width=80% border=2> 
<thead> 
<tr> 
<tr> <th>Data</th> 
<th>Cognome</th> 
<th>Nome</th> 
<th>Data di Nascita</th> 
<th>Luogo di nascita</th> 
<th>Luogo del fatto</th> 
<th>Ora</th> </tr><br /> 
</thead> "; 

while ($riga = mysql_fetch_assoc($risultato)) { 

$contenuto .= "<td>".$riga["data"]."</td>"; 
$contenuto .= "<td>".$riga["cognome"]."</td>"; 
$contenuto .= "<td>".$riga["nome"]."</td>"; 
$contenuto .= "<td>".$riga["data_nasc"]."</td>"; 
$contenuto .= "<td>".$riga["luogo"]."</td>"; 
$contenuto .= "<td>".$riga["luogo_fatto"]."</td>"; 
$contenuto .= " <td>".$riga["ora"]."</td>"; 
$contenuto .= "<tr><th colspan='14' align = center>Fatto</th><tr><td colspan='14' align = center>".$riga["fatto"]."</td></tr>"; 
$contenuto .= " <tr><th colspan='14'>Descrizione del fatto</th></tr><tr><td colspan='14' align = justify>".$riga["descri"]."</td></tr>"; 

} 

我该怎么办?

+0

否您的循环中的标记在第一个​​之前 – Krazibit312

回答

0

只需插入,而里面的代码..

while ($riga = mysql_fetch_assoc($risultato)) { 

    <thead> 
     <tr> 
     <tr> <th>Data</th> 
      <th>Cognome</th> 
      <th>Nome</th> 
      <th>Data di Nascita</th> 
      <th>Luogo di nascita</th> 
      <th>Luogo del fatto</th> 
      <th>Ora</th> </tr><br /> 
    </thead> ";     


} 
0
$head='*head html sentence*'; 

而($里加= mysql_fetch_assoc($ risultato)){

$contenuto .= $head; 
$contenuto .= "<td>".$riga["data"]."</td>"; 
$contenuto .= "<td>".$riga["cognome"]."</td>"; 
$contenuto .= "<td>".$riga["nome"]."</td>"; 
$contenuto .= "<td>".$riga["data_nasc"]."</td>"; 
$contenuto .= "<td>".$riga["luogo"]."</td>"; 
$contenuto .= "<td>".$riga["luogo_fatto"]."</td>"; 
$contenuto .= " <td>".$riga["ora"]."</td>"; 
$contenuto .= "<tr><th colspan='14' align = center>Fatto</th><tr><td colspan='14' align = center>".$riga["fatto"]."</td></tr>"; 
$contenuto .= " <tr><th colspan='14'>Descrizione del fatto</th></tr><tr><td colspan='14' align = justify>".$riga["descri"]."</td></tr>"; 

}

1

这人会帮你简单地把标题部分放在里面

echo "<table align = center width=80% border=2>"; 
$contenuto="<thead> 
    <tr> <th>Data</th> 
    <th>Cognome</th> 
     <th>Nome</th> 
     <th>Data di Nascita</th> 
     <th>Luogo di nascita</th> 
     <th>Luogo del fatto</th> 
     <th>Ora</th> </tr> 
     </thead> "; 

     while ($riga = mysql_fetch_assoc($risultato)) { 
      echo $contenuto. "<td>".$riga["data"]."</td><td>".$riga["cognome"]."</td><td>".$riga["nome"]."</td><td>".$riga["data_nasc"]."</td> <td>".$riga["luogo"]."</td><td>".$riga["luogo_fatto"]."</td><td>".$riga["ora"]."</td> </tr> 

     <tr><th colspan='14' align = center>Fatto</th></tr> 

     <tr><td colspan='14' align = center>".$riga["fatto"]."</td></tr> 

      <tr><th colspan='14'>Descrizione del fatto</th></tr><tr><td colspan='14' align = justify>".$riga["descri"]."</td></tr>"; 
     } 

您错过了几个tr标签。我加了那两个。这一个将帮助你确定。