【问题标题】:How to display information from my database to html table?如何将我的数据库中的信息显示到 html 表中?
【发布时间】:2017-05-25 21:53:08
【问题描述】:

目前我正在尝试显示我收到的所有插入到我的数据库中的付款(payment_history) html 表,但我在 phpmyadmin 上的 SQL 表中有多个用户。

PHP 端代码。

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class payment_history_model extends MY_Model {
public function __construct(){
    parent::__construct();
}

public function getPaymentHistory(){
    $accounts = $this->model->fetch("*", PAYMENT_HISTORY, getDatabyUser(0), "id", "asc");
    if(!empty($accounts)){
        foreach ($accounts as $key => $row) {
            $user = $this->model->get("*", USER_MANAGEMENT, "id = '".$row->uid."'");
            if(!empty($user)){
                $accounts[$key]->user = $user->fullname;
            }else{
                $accounts[$key]->user = "";
            }
        }
    }

    return $accounts;
}
}

我的 html 表格代码。

<thead>
    <tr>
        <th><?=l('User')?></th> 
        <th><?=l('Invoice')?></th> 
        <th><?=l('First name')?></th>
        <th><?=l('Last name')?></th>
        <th><?=l('Receiver email')?></th>
        <th><?=l('Payer email')?></th>
        <th><?=l('Package')?></th>
        <th><?=l('Price')?></th>
        <th><?=l('Currency')?></th>
        <th><?=l('Street')?></th>
        <th><?=l('City')?></th>
        <th><?=l('Country')?></th>
        <th><?=l('Payment date')?></th>
        <th><?=l('Payment status')?></th>
        <th><?=l('Option')?></th>
    </tr>
</thead>
<tbody>
    <?php  
        if(!empty($result)){
        foreach ($result as $key => $row) {
    ?>
    <tr class="pending" data-action="<?=cn('ajax_action_item')?>" data-id="<?=$row->id?>">
        <td>
            <input type="checkbox" name="id[]" id="md_checkbox_<?=$key?>" class="filled-in chk-col-red checkItem" value="<?=$row->id?>">
            <label class="p0 m0" for="md_checkbox_<?=$key?>">&nbsp;</label>
        </td>
        <td><a href="<?=url('user_management/update?id='.$row->uid)?>"><?=$row->user?></a></td> 
        <td><?=$row->invoice?></td> 
        <td><?=$row->first_name?></td>
        <td><?=$row->last_name?></td>
        <td><?=$row->receiver_email?></td>
        <td><?=$row->payer_email?></td>
        <td><?=$row->item_name?></td>
        <td><?=$row->mc_gross?></td>
        <td><?=$row->mc_currency?></td>
        <td><?=$row->address_street?></td>
        <td><?=$row->address_city?></td>
        <td><?=$row->address_country?></td>
        <td><?=$row->payment_date?></td>
        <td><?=$row->payment_status?></td>
        <td><?=$row->Option?></td>
    </tr>
</tbody>

【问题讨论】:

  • 你到底想做什么?
  • @Eitan 将数据库行发布到我的 html 表中。但它只显示我的数据库中的 1 个用户,但数据库中的用户超过 1 个。
  • 我没有看到你使用任何类型的模型,你有吗?
  • 这和 Laravel 有什么关系?标记所以我来到这里,但这是普通的 php 或其他框架,查看第二个代码块中的语法。
  • 正如上面所说的那样,我的朋友我真的没有看到 laravel

标签: php html mysql html-table


【解决方案1】:

好的,你的类 MyModel 来自 http://pastebin.com/Vc8tUvpH 包含 fetch 方法:

function fetch($select = "*", $table = "", $where = "", $order = "", $by = "DESC", $start = -1, $limit = 0, $return_array = false)
{
...
}

现在,我们可以说问题出在$where = getDatabyUser(0)

getDatabyUser(0) 很可能会添加 where clause,这会将您的结果限制为一行。

你应该试试:

  • 输出getDatabyUser(0) 喜欢var_dump(getDatabyUser(0))
  • 打开phpmyadmin并添加相同的where子句并检查结果

现在您似乎正在尝试获取 user with ID = 0 的付款历史记录。

您也可以通过将getDatabyUser(0) 替换为“”(空字符串)来检查它。

public function getPaymentHistory(){
    $accounts = $this->model->fetch("*", PAYMENT_HISTORY, "", "id", "asc");
    if(!empty($accounts)){
        foreach ($accounts as $key => $row) {
            $user = $this->model->get("*", USER_MANAGEMENT, "id = '".$row->uid."'");
            if(!empty($user)){
                $accounts[$key]->user = $user->fullname;
            }else{
                $accounts[$key]->user = "";
            }
        }
    }

    return $accounts;
}

【讨论】:

    猜你喜欢
    • 2014-04-22
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 2014-01-15
    • 2017-08-15
    相关资源
    最近更新 更多