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 your table
$retrieve_data = $wpdb->get_results( "SELECT * FROM wpex_programma; " );
print_r($retrieve_data);
?>
<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? The table name is correct, and I have data in my database tabel. The print_r($retrieve_data)
returns the following:
Array ( [0] => stdClass Object ( [id] => 35 [naam] => /public_html/wp/wp-content/plugins/AbonneerProgrammas/FilesUpload/Country Kickin 1.mp3 ) )
My query log:
New:
<?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 your table
$retrieve_data = $wpdb->get_results( "SELECT * FROM wpex_programma; " );
print_r($retrieve_data);
?>
<ul>
<?php foreach ($retrieve_data as $retrieved_data){ ?>
<li><?php echo $retrieved_data->id;?></li>
<li><?php echo $retrieved_data->naam;?></li>
<?php
}
?>
</ul>
$table_name = $wpdb->prefix . "wpex_programma";
? – Parsa_237 Mar 12 '20 at 10:48