Display data from database inside <table> using wordpress $wpdb Display data from database inside <table> using wordpress $wpdb wordpress wordpress

Display data from database inside <table> using wordpress $wpdb


Try this:

<table border="1"><tr> <th>Firstname</th> <th>Lastname</th> <th>Points</th></tr>  <?php    global $wpdb;    $result = $wpdb->get_results ( "SELECT * FROM myTable" );    foreach ( $result as $print )   {    ?>    <tr>    <td><?php echo $print->firstname;?></td>    </tr>        <?php }  ?>              


You're missing . in echo '<td>' $print->firstname.'</td>';

Try this

<?php  global $wpdb;  $result = $wpdb->get_results ( "SELECT * FROM myTable" );    foreach ( $result as $print )   {      echo '<tr>';      echo '<td>' . $print->firstname.'</td>';      echo '<td>' . $print->lastname.'</td>';      echo '<td>' . $print->points.'</td>';      echo '</tr>';  }?>  


Try this:

$result = $wpdb->get_results("SELECT * FROM myTable" , ARRAY_A); //get result as associative array

Then the usual cycle:

//spare memory$count = count($result);//fastest way to perform the cyclefor ($i = $count; $i--;) {   echo '<td>'. $print[$i]['firstname'].'</td>';}