显示来自< table>内的数据库的数据使用wordpress $ wpdb [英] Display data from database inside <table> using wordpress $wpdb

查看:138
本文介绍了显示来自< 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 }
  ?>              

这篇关于显示来自&lt; table&gt;内的数据库的数据使用wordpress $ wpdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆