显示来自< table>内的数据库的数据使用wordpress $ wpdb
问题描述:
有人可以帮助我,如何编写逻辑以将数据从我的数据库打印到< table>
?
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 im really having a hard time to make this work.
答
试试这个:
<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 }
?>