Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving and displaying data from Wordpress database

At the moment, I have created a code that retrieves data from the database and displays it. However, for some reason, I cannot see the files I want to retrieve on my page. My goal is that the data gets retrieved from the database, and is displayed on the webpage. I do not need to make a connection with the database since Wordpress does that automatically.

My code:

<?php

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

My question: the data is not shown and I believe it is not retrieved. How can I fix that?

My database structure:

enter image description here


1 Answers

You can check the data from your database table. In PHP MySQL database. you can find the table name after the prefix of the table which you have decided while installing the WordPress. there should be your column name exact. with the table name.

like image 200
M Umair Avatar answered Sep 15 '25 15:09

M Umair