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

时间:2015-06-11 08:10:10

标签: php wordpress themes

我正在使用我在wordpress中安装和激活的主题。主题是Zerif-lite。

我在名为“doctors”的数据库中添加了一个表,其中包含2个属性“id”和“name”。 我要做的是选择此表中的所有数据。 我使用了以下代码,但没有显示任何内容

;with data as
(
    select
        ROW_NUMBER() OVER (ORDER BY date) AS number, 
        ROW_NUMBER() OVER (PARTITION BY first, second, third, fourth ORDER BY date) AS part,
        *
    from roster
)
select MIN(date) as startdate, MAX(date) as enddate, COUNT(*) count, first, second, third, fourth
from data group by first, second, third, fourth, number - part
order by number - part

任何帮助??

2 个答案:

答案 0 :(得分:1)

  

试试这个

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

答案 1 :(得分:0)

试试这个:

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