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

126 views Asked by At

I am using a theme that i installed and activated in wordpress .The theme is Zerif-lite.

I added a table to the database named "doctors" with 2 attributes "id" and "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??

2

There are 2 answers

0
bhavesh vala On BEST ANSWER

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;
}
0
vrajesh On

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;
}