2014-01-22 54 views
0

我對WordPress非常陌生;我想知道是否有人能夠讓我知道如何在WordPress的一個頁面中以表格格式添加我的一個數據庫表格;我做了一個研究,我發現這個:http://www.youtube.com/watch?v=hb3lfwq1bfM,但我不知道「wpData Tables」是否是我需要安裝的插件或...?我在wordpress中沒有這個選項!顯示WordPress中表格中的數據庫數據

如果您需要更多說明,請讓我知道。

如果有人能告訴我正確的方向,我很感激:)

感謝

回答

1

在您的page.php文件在需要區域內循環添加該代碼。

替換$my_page_id,$table_name的值,並根據您的要求添加列。

<?php 
$my_page_id = 111; // page ID here 
if(get_the_ID() === $my_page_id) { 

global $wpdb; 
$table_name = 'your_table_name_here'; 
$myrows = $wpdb->get_results("SELECT column_1, column_2, column_3 FROM ". $table_name); // add columns as you want 
?> 
<table> 
    <thead> 
     <tr> 
      <th>Column 1</th> 
      <th>Column 2</th> 
      <th>Column 3</th> 
     </tr> 
    </thead> 
    <tbody> 
    <?php foreach ($myrows as $myrow) { ?> 
     <tr> 
      <td><?php echo $myrow->column_1; ?></td> 
      <td><?php echo $myrow->column_2; ?></td> 
      <td><?php echo $myrow->column_3; ?></td> 
     </tr> 
    <?php } ?> 
    </tbody> 
</table> 
<?php 
} 
+0

嗨,Omair,對不起,如果我問一個愚蠢的問題;但這個page.php在哪裏?這是完全一樣的名字嗎?抱歉,我對WP非常陌生!假設你在page.php中創建了一個新項目?謝謝 – user385729

+1

page.php位於:'/ wp-content/themes/{theme-name}/page.php'在你的web服務器上。以下是您可以如何找到頁面ID:http://goo.gl/QTdkPJ。我希望你知道你想要檢索的數據庫表名稱和列名:')' –

+0

YEa我知道:D但是它是像PHP還是......我們需要通過數據庫配置,如主機,密碼,DBname?如果是這樣,我應該通過這些配置?你是非常有幫助的人。謝謝:) – user385729