目前,我創建了一個從數據庫中檢索數據并顯示它的代碼。但是,由于某種原因,我在頁面上看不到要檢索的文件。我的目標是從數據庫中檢索數據,并顯示在網頁上。我不需要與數據庫建立連接,因為 Wordpress 會自動連接。我的代碼:<?phpglobal $wpdb;// this adds the prefix which is set by the user upon instillation of wordpress$table_name = $wpdb->prefix . "wpex_programma";// this will get the data from my table$retrieve_data = $wpdb->get_results( "SELECT * FROM wpex_programma" );?><!--This will display my files--><ul><?php foreach ($retrieve_data as $retrieved_data){ ?><li><?php echo $retrieved_data->column_name;?></li><li><?php echo $retrieved_data->another_column_name;?></li><li><?php echo $retrieved_data->as_many_columns_as_you_have;?></li><?php }?></ul>我的問題:數據沒有顯示,我相信它沒有被檢索到。我該如何解決?我的數據庫結構:
2 回答

小唯快跑啊
TA貢獻1863條經驗 獲得超2個贊
這是一個示例代碼,它將獲取數據然后顯示它
global $wpdb;
// this adds the prefix which is set by the user upon instillation of wordpress
$table_name = $wpdb->prefix . "wpex_programma";
// this will get the data from your table
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
?>
<ul>
foreach ($retrieve_data as $retrieved_data){ ?>
<li><?php echo $retrieved_data->id;?></li>
<li><?php echo $retrieved_data->naam;?></li>
<li><?php echo $retrieved_data->as_many_columns_as_you_have;?></li>
<?php
}
?>
確保您創建了一個數據庫,
確保添加正確的 table_name,
確保您已在表中插入數據。
- 2 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消