简体   繁体   English

如何从php中的wordpress数据库中检索数据并显示在页面上?

[英]How to retrieve data from wordpress database in php and display on a page?

I am using a theme that i installed and activated in wordpress .The theme is Zerif-lite. 我正在使用在wordpress中安装并激活的主题。该主题是Zerif-lite。

I added a table to the database named "doctors" with 2 attributes "id" and "name". 我在数据库中添加了一个名为“ doctors”的表,它具有2个属性“ id”和“ name”。 What I'm trying to do is to select all data in this table. 我想做的是选择此表中的所有数据。 I've used the following code but nothing is displayed 我使用了以下代码,但是什么也没有显示

$mystuff = $wpdb->get_row("SELECT * FROM doctors WHERE 1);

Any Help?? 有帮助吗?

try this 尝试这个

global $wpdb;
$result = $wpdb->get_results("select * from `table_name` where column = value");
foreach($result as $results){
  echo $results->field1;
  echo $results->field2;
}

try this: 尝试这个:

global $wpdb;
$result = $wpdb->get_results("select * from `table_name`");
foreach($result as $row){
echo $row->field1;
echo $row->field2;
echo $row->field3;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM