<?php $results = $wpdb->get_results( "SELECT * FROM $table_name"); // Query to fetch data from database table and storing in $results if(!empty($results)) // Checking if $results have some values or not { echo "<table width='100%' border='0'>"; // Adding <table> and <tbody> tag outside foreach loop so that it wont create again and again echo "<tbody>"; foreach($results as $row){ $userip = $row->user_ip; //putting the user_ip field value in variable to use it later in update query echo "<tr>"; // Adding rows of table inside foreach loop echo "<th>ID</th>" . "<td>" . $row->id . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>User IP</th>" . "<td>" . $row->user_ip . "</td>"; //fetching data from user_ip field echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>Post ID</th>" . "<td>" . $row->post_id . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>Time</th>" . "<td>" . $row->time . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; } echo "</tbody>"; echo "</table>"; } ?>