2012-05-28 44 views
0

好吧,所以我有一個上傳系統在我的網站上,用戶可以上傳文件並寫下他們的簡要說明。每個上傳都有一個對應的SQL條目。概念幫助需要:表格和顯示所有行

我的網站上,然後將顯示有關文件的一些特徵一起上傳的每一個文件的另一頁

的問題是:

如何創建一個表變量組行,我怎麼可以設置一個表來自動填充新行。

我能用PHP,但仍然是新手。用HTML(我使用wysiwyg)並且完全沒有Javascript經驗。

在正確的方向輕推任意將非常感激......

+1

如果您瞭解html表的結構,問題在哪裏? –

回答

0

爲了使你的HTML表格的行「動態」使用PHP,你應該使用foreach()控制結構。例如,假設您有一些代碼從數據庫中獲取數據,並將其作爲數組或某種實現Iterable接口的結果語句返回(我們將其稱爲$results),那麼您可以:

<table> 

<thead> 
    <tr> 
     <th>File Name</th> 
     <th>Description</th> 
    </tr> 
</thead>  

<tbody> 
<?php 
    foreach($results as $result) 
    { 
     // Start row 
     echo("<tr>"); 

     echo("<td>" . $result->filename . "</td>"); 
     echo("<td>" . $result->description . "</td>"); 

     // End row 
     echo("</tr>"); 
    } 
?> 
</tbody> 

</table> 
<table> 

<thead> 
    <tr> 
     <th>File Name</th> 
     <th>Description</th> 
    </tr> 
</thead>  

<tbody> 
<?php 
    foreach($results as $result) 
    { 
     // Start row 
     echo("<tr>"); 

     echo("<td>" . $result->filename . "</td>"); 
     echo("<td>" . $result->description . "</td>"); 

     // End row 
     echo("</tr>"); 
    } 
?> 
</tbody> 

</table> 
0

可以使用循環根據數據庫查詢的結果填充表。下面是我用我的一個網頁代碼:

$result = $db->query_read("SELECT dice.RollID AS `Roll`, dice.Limit AS `Limit`, 
dice.Value AS `Value`, dice.Dateline AS `Dateline`, dice.Comment AS `Comment` 
FROM dice 
ORDER BY Dateline DESC LIMIT 25"); 

// ###### MAIN CODE ###### 
$str = '<table> 
<tr><th>ID</th><th>Roll</th><th>Time</th><th>Comment</th></tr>'; 

while ($resultLoop = $db->fetch_array($result)) { 

    $ID = $resultLoop["Roll"]; 
    $roll = $resultLoop["Value"] . '/' . $resultLoop["Limit"]; 
    $when = date('m-d-Y H:i:s', $resultLoop["Dateline"]); 
    $comment = $resultLoop["Comment"]; 

    $str .= '<tr> 
    <td>' . $ID . '</td> 
    <td>' . $roll . '</td> 
    <td>' . $when . '</td> 
    <td>' . $comment . '</td></tr>'; 
} 

$str .= '</table>'; 
echo $str; 

有一點要注意的是,我用$ DB - > *功能,因爲它與論壇軟件集成。您應該使用mysqli_ *函數,如下所示:http://php.net/manual/en/book.mysqli.php