0

I have created a Custom Post Type by name “Project” and a Custom Database table named wp_project_db for it.

The wp_project_db consist of 4 Columns – order_id, user_id, project_id and reward_amount.

My question is that I want to fetch & display the data from the table mentioned above on the project page.

I used following code to display:

<?php
global $wpdb;
$customers = $wpdb->get_results("SELECT * FROM wp_project_db");
?>

<table class="table table-hover">

<?php foreach($customers as $customer){ ?>

<tr>
 <td><center><?php echo $customer->order_id; ?></center></td>
 <td><center><?php echo $customer->user_id; ?></center></td>
 <td><center><?php echo $customer->project_id; ?></center></td>
 <td><center><?php echo $customer->reward_amount; ?></center></td>
</tr>

<?php } ?>

</table>

The problem is that the above code displays whole data from the database table.

I want to display data related to every project on that particular project page dynamically.

Plz help, Thanks.

  • 1
    Sorry, but your question is too vague. Please explain what you mean by "the above code displays whole data from the database table" and "display data related to every project on that particular project page dynamically". In our SQL you are doing a query for all rows. To specify which rows (say by user_id or project_id you will need to add a WHERE clause (techonthenet.com/mysql/where.php) – danbrellis Jul 19 '17 at 11:41
  • @danbrellis, When I add this code on the project page, I am getting whole data from the table. Actually I want to display only the data that is related to the particular project. Each project page should display their respective data dynamically. – Minesh Jul 19 '17 at 12:09
  • Gotcha, so you will need to add a WHERE clause into your MYSQL statement. Do you have a URL I can see? I assume you'll want to pull the project ID from the URL to use in your query. – danbrellis Jul 19 '17 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.