Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all rows from table and display specific column data from wordpress database

I have table called wp_email_subscription and inside table I have rows of emails from subscribed users. Each row contains id, email, and name column.

I have also created admin page for plugin where I would like to list all emails from subscribed table.

Basically I don't know how to use wpdb functions, I have read wpdb instructions from wp website but I don't understand.

what I need is to select all from wp_email_subscription and foreach row to display email and name column in list.

like image 763
lonerunner Avatar asked Nov 07 '12 04:11

lonerunner


People also ask

How do I make a table list in WordPress?

Creating Tables in the WordPress Block Editor Simply create a new post or page, or edit an existing one. Once inside the content editor, click on the (+) symbol to add a new block, then select 'Table'. You can find it under the 'Formatting' section ,or you can type 'Table' into the 'Search for a block' bar.

How do I display MySQL table data in WordPress?

The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.


1 Answers

you have to use global wpdp variable and get_result function in your code page like this...

global $wpdb;

$row = $wpdb->get_results( "SELECT * FROM wp_email_subscription");

foreach ( $row as $row ) 
{ echo "email:".$row->email.";} //$row->your_column_name in table

like this, you can access all columns by $variable->col_name

like image 188
Prakash Pala Avatar answered Sep 25 '22 14:09

Prakash Pala