什麼,你正在努力實現主要是:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab 1</a></li>
<li><a href="#tabs-2">Tab 2</a></li>
<li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
<table> <!-- Rest of the table1 --> </table>
</div>
<div id="tabs-2">
<table> <!-- Rest of the table2 --> </table>
</div>
<div id="tabs-3">
<table> <!-- Rest of the table3 --> </table>
</div>
</div>
你可以使用PHP代碼來創建這些表(我假設你已經查詢數據庫,並有在變量$行中的數據):
<div id="tabs-1">
<table>
<?php foreach ($rows as $data)
{
echo "<tr>";
echo "<td>". $data['attribute1'] . "</td><td>". $data['attribute2'] . "</td>"";
echo "</tr>";
}
?>
</table>
</div>
好了,上面的代碼不一定完整,可以添加表頭,用CSS等按照您的要求裝飾。但是使用這種方法,您將不得不重複每個表的代碼。既然你說你在三個標籤中都有相同的表格結構,你可以在它自己的循環中創建div標籤。在這種情況下,您將擁有:
for(loop as many tabs you want) {
echo "<div id='tabs-'".index.">";
/* Query DB and get the data into $rows variable */
foreach ($rows as $data) {
echo "<tr>";
echo "<td>". $data['attribute1'] . "</td><td>". $data['attribute2'] . "</td>"";
echo "</tr>";
}
echo "</div>";
}
同樣,您需要按照您的要求進行裝飾。這些代碼片段可以幫助您開始!
你有一個php變量與查詢結果嗎? – Orbit 2011-03-02 06:07:08
不需要。我想通過點擊選項卡來完成,然後將其保存到數組中。第一個選項卡的查詢應該在頁面加載時運行並填充表格。 – y2p 2011-03-02 06:11:45
在這種情況下,爲什麼在用戶激活選項卡時不使用ajax加載數據? – 2011-03-02 06:21:14