2016-08-17 45 views
-1

基本上我希望输出与thead匹配并对齐。我尝试了一些方法,只创造了更多的错误。我对编码非常陌生,我感谢所有来过的人,并回答了问题,因为答案已经让我走到了尽头。将Mysql的输出格式化为表格和新行

例子:http://nightsins.net/nhlrealgm/test/ 输入任何积极的NHL球员的姓氏即克罗斯比

的tablehead下输出我只是无法弄清楚如何以正确格式并加入到表头。第二个问题是说你输入“Cros”,它会在同一行上返回2个结果。下班后会\ n吗?以下是我使用的代码减去任何标记格式。谢谢你,

<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > 
<thead> 
    <tr> 
     <th>Player</th> 
     <th>POS</th> 
     <th>16-17 Fpts</th> 
     <th>16-17 Fpts/G</th> 
     <th>15-16 Fpts</th> 
     <th>15-16 Fpts/G</th> 
     <th>14-15 Fpts</th> 
     <th>14-15 Fpts/G</th> 
     <th>13-14 Fpts</th> 
     <th>13-14 Fpts/G</th> 
    </tr> 
</thead> 
</table> 

<?php 
    $i=1; 
    while($results = mysql_fetch_assoc($raw_results)){ 
?> 
<tbody> 
    <tr> 
     <td><?php echo $results['Name']; ?></td> 
     <td><?php echo $results['Pos']; ?></td> 
     <td><?php echo $results['FPts16']; ?></td> 
     <td><?php echo $results['FPG16']; ?></td> 
     <td><?php echo $results['FPts15']; ?></td> 
     <td><?php echo $results['FPG15']; ?></td> 
     <td><?php echo $results['FPts14']; ?></td> 
     <td><?php echo $results['FPG14']; ?></td> 
     <td><?php echo $results['FPts13']; ?></td> 
     <td><?php echo $results['FPG13']; ?></td> 
    </tr> 
<?php 
$i++; 
    } 
?> 
    </tbody> 

<?php 

    } 
    else 
    { 
     echo "Player not found."; 
    } 

} 
else 
{ 
    echo "Minimum length is ".$min_length; 
} 
?> 
</body> 
</html> 
+0

你完成 –

回答

0
Your just adding <tbody> in ur while loop. remove and close u r table after tbody 

<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > 
    <thead> 
     <tr> 
      <th>Player</th> 
      <th>POS</th> 
      <th>16-17 Fpts</th> 
      <th>16-17 Fpts/G</th> 
      <th>15-16 Fpts</th> 
      <th>15-16 Fpts/G</th> 
      <th>14-15 Fpts</th> 
      <th>14-15 Fpts/G</th> 
      <th>13-14 Fpts</th> 
      <th>13-14 Fpts/G</th> 
     </tr> 
    </thead> 
    <tbody> 

    <?php 
     $i=1; 
     while($results = mysql_fetch_assoc($raw_results)) 
{ 
    ?> 

     <tr> 
      <td><?php echo $results['Name']; ?></td> 
      <td><?php echo $results['Pos']; ?></td> 
      <td><?php echo $results['FPts16']; ?></td> 
      <td><?php echo $results['FPG16']; ?></td> 
      <td><?php echo $results['FPts15']; ?></td> 
      <td><?php echo $results['FPG15']; ?></td> 
      <td><?php echo $results['FPts14']; ?></td> 
      <td><?php echo $results['FPG14']; ?></td> 
      <td><?php echo $results['FPts13']; ?></td> 
      <td><?php echo $results['FPG13']; ?></td> 
     </tr> 
    <?php 
    $i++; 
     } 
    ?> 
     </tbody> 
</table> 
    <?php 

     } 
     else 
     { 
      echo "Player not found."; 
     } 

    } 
    else 
    { 
     echo "Minimum length is ".$min_length; 
    } 
    ?> 
    </body> 
    </html> 
+0

谢谢你,我确定我不会过早地关闭标签再次使这个简单的错误。 – nightsins

0
Use the code as follows. You just need to put the tbody outside the while loop. 



<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > 
    <thead> 
     <tr> 
      <th>Player</th> 
      <th>POS</th> 
      <th>16-17 Fpts</th> 
      <th>16-17 Fpts/G</th> 
      <th>15-16 Fpts</th> 
      <th>15-16 Fpts/G</th> 
      <th>14-15 Fpts</th> 
      <th>14-15 Fpts/G</th> 
      <th>13-14 Fpts</th> 
      <th>13-14 Fpts/G</th> 
     </tr> 
</thead> 
    <tbody>  
    <?php 
     $i=1; 
     while($results = mysql_fetch_assoc($raw_results)){ 
    ?> 
     <tr> 
      <td><?php echo $results['Name']; ?></td> 
      <td><?php echo $results['Pos']; ?></td> 
      <td><?php echo $results['FPts16']; ?></td> 
      <td><?php echo $results['FPG16']; ?></td> 
      <td><?php echo $results['FPts15']; ?></td> 
      <td><?php echo $results['FPG15']; ?></td> 
      <td><?php echo $results['FPts14']; ?></td> 
      <td><?php echo $results['FPG14']; ?></td> 
      <td><?php echo $results['FPts13']; ?></td> 
      <td><?php echo $results['FPG13']; ?></td> 
     </tr> 
    <?php 
    $i++; 
     } 
    ?> 
     </tbody> 

    <?php 

     } 
     else 
     { 
      echo "<tr><td colspan=10>Player not found.</td></tr>"; 
     } 

    } 
    else 
    { 
     echo "Minimum length is ".$min_length; 
    } 
    ?> 
    </body> 
    </html> 
+0

谢谢 - 你们真棒。 – nightsins

0

似乎是if语句。不过IM下面的代码,并在此基础上,我发现你已经结束了,你没有提供的支架不会终结正确完整的代码你</table>只是在</thead>之后,应该不是这种情况。

取而代之,您应该在</tbody>之后关闭,并且您还没有向我们显示您的if语句的起始位置。我希望它已在<table>标记之前开始。

于是我想出了下面的代码,并希望这是有道理..

<?php 

if(2 == 2) // your main if starts which will check your length 
{ 
    if(1 == 1) 
    { // this if statement is to find a player 
?> 
      <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > 
      <thead> 
       <tr> 
        <th>Player</th> 
        <th>POS</th> 
        <th>16-17 Fpts</th> 
        <th>16-17 Fpts/G</th> 
        <th>15-16 Fpts</th> 
        <th>15-16 Fpts/G</th> 
        <th>14-15 Fpts</th> 
        <th>14-15 Fpts/G</th> 
        <th>13-14 Fpts</th> 
        <th>13-14 Fpts/G</th> 
       </tr> 
      </thead> 


      <?php 
       $i=1; 
       while($results = mysql_fetch_assoc($raw_results)){ 
      ?> 
      <tbody> 
       <tr> 
        <td><?php echo $results['Name']; ?></td> 
        <td><?php echo $results['Pos']; ?></td> 
        <td><?php echo $results['FPts16']; ?></td> 
        <td><?php echo $results['FPG16']; ?></td> 
        <td><?php echo $results['FPts15']; ?></td> 
        <td><?php echo $results['FPG15']; ?></td> 
        <td><?php echo $results['FPts14']; ?></td> 
        <td><?php echo $results['FPG14']; ?></td> 
        <td><?php echo $results['FPts13']; ?></td> 
        <td><?php echo $results['FPG13']; ?></td> 


       </tr> 
      <?php 
      $i++; 
       } 
      ?> 
       </tbody> 
       </table> 
<?php 

    } // if statement to find a player ends 
    else 
    { 
     echo "Player not found."; 
    } 

} // if statement to find a length ends 
else 
{ 
    echo "Minimum length is ".$min_length; 
} 
?> 

</body> 
</html>