php – 使用wordpress $wpdb显示数据库内部的数据

有人可以帮助我,如何编写逻辑来将数据从我的数据库打印到 table?table border=1trthFirstname/ththLastname/ththPoints/th/trtr?phpglobal $wpdb;$result = $wpdb-get_results ( SELECT...

有人可以帮助我,如何编写逻辑来将数据从我的数据库打印到< 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>

我知道这是如此基本,但我真的很难让这项工作.

解决方法:

试试这个:

<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 }
  ?>              

本文标题为:php – 使用wordpress $wpdb显示数据库内部的数据

基础教程推荐