2015-12-16 109 views
3

我有一個排行榜,它告訴我什麼人與他們的貨幣(虛擬貨幣爲測試目的)ontop。 所以它的工作原理,它顯示了從我的表到PDO(PHP數據對象)的一切。我的pdo結果複製到表

問題是,我讓它在表中輸出。但對於每一個ID那裏有正在取得第二表是這樣的:

enter image description here

代碼即時通訊使用:

<?php 
$db = new PDO('mysql:host=localhost;dbname=test1','root','####'); 

$sql = "SELECT naam, id, days, money FROM user ORDER BY money DESC "; 
$results = $db->query($sql); 



foreach($results as $row) 
{ 

?> 


<html> 
<head> 



</head> 
<body> 
<TABLE BORDER="5" WIDTH="100%" CELLPADDING="4" CELLSPACING="3"> 
    <TR> 
     <TH><BR><H3>POINTS LEADERBOARD</H3> 
     </TH> 
    </TR> 
    <TR> 
     <TH>Username</TH> 
     <TH>Money</TH> 
     <TH>Days</TH> 
    </TR> 
    <TR> 
     <TD><?php echo $row['naam']; ?></TD> 
     <TD><?php echo $row['money']?></TD> 
     <TD><?php echo $row['days']?></TD> 
    </TR> 
</TABLE> 

<?php 
/* 
echo "<table>"; 
echo "<TR>"; 
    echo "<TH><BR><H3>POINTS LEADERBOARD</H3>"; 
    echo "</TH>"; 
echo "</TR>"; 

echo "<TR>"; 
echo "<TH>Username</TH>"; 
echo "<TH>Money</TH>"; 
echo "<TH>Days</TH>"; 
echo "</TR>"; 

echo "<TR>"; 
    echo "<TD>"; echo $row['naam']; echo "</TD>"; 
    echo "<TD>"; echo $row['money']; echo "</TD>"; 
    echo "<TD>"; echo $row['days']; echo "</TD>"; 
echo "</TR>"; 
echo "</table>"; 
*/ 
?> 




<?php } ?> 
</body> 
</html> 

誰能幫助我,或告訴我什麼即時做錯了什麼?

謝謝!

+1

請告訴周圍的HTML代碼,例如循環 – Steve

+0

不能爲整個腳本 – RamRaider

+0

不,我現在 –

回答

2

你在循環中打開html etc標籤的方式是錯誤的 - 也許是這樣的?

<?php 
    $db = new PDO('mysql:host=localhost;dbname=test1','root','####'); 
    $sql = 'SELECT naam, id, days, money FROM user ORDER BY money DESC '; 
    $results = $db->query($sql); 
?> 
<html> 
    <head> 
     <title>leaderboard</title> 
    </head> 
    <body> 
     <?php 
     echo " 
      <TABLE BORDER='5' WIDTH='100%' CELLPADDING='4' CELLSPACING='3'> 
       <TR> 
        <TH><BR><H3>POINTS LEADERBOARD</H3></TH> 
       </TR> 
       <TR> 
        <TH>Username</TH> 
        <TH>Money</TH> 
        <TH>Days</TH> 
       </TR>"; 

     foreach($results as $row) { 
      echo " 
       <TR> 
        <TD>{$row['naam']}</TD> 
        <TD>{$row['money']}</TD> 
        <TD>{$row['days']}</TD> 
       </TR>"; 
     } 
     echo "</TABLE>"; 
     ?> 
    </body> 
</html> 
+0

這段代碼工作的一半:D,它的工作原理是這樣的:它不再複製它,但它只複製表頭像用戶名錢和天 –

+0

Aaah我修好了,把TH也放在了Foreach上面, –

+0

只把行內的行 – coopwatts