Can someone help me, how to code the logic to print the data from my database into a <table>
?
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM myTable" );
foreach ( $result as $print ) {
echo '<td>' $print->firstname.'</td>';
}
?>
</tr>
</table>
I know this is so basic, but I’m having a hard time making this work.
Try this:
You’re missing
.
inecho '<td>' $print->firstname.'</td>';
Try this
Try this:
Then the usual cycle:
You just need to put
<tr>
inside your foreach loop, and add.
concatenation operator in your line, you need also try this :You need to wrap
<td></td>
inside<tr></tr>
in foreach loopYou need to add
.
concatenation operator in line that contains firstname variable.If you have duplicate values, then add this parameter
ARRAY_A
to your query$result = $wpdb->get_results ( "SELECT * FROM myTable",ARRAY_A );
.