目前,我创建了一个从数据库中检索数据并显示它的代码。但是,由于某种原因,我在页面上看不到要检索的文件。我的目标是从数据库中检索数据,并显示在网页上。我不需要与数据库建立连接,因为 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 关注
- 105 浏览
添加回答
举报
0/150
提交
取消