如何将数据库中的信息显示到html表?

时间:2017-01-11 07:41:56

标签: php html mysql html-table

目前我正在尝试显示我收到的所有已插入到我的数据库中的付款(payment_history)我想在html表格中显示它们,但每次我尝试时,它只显示我1个用户在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>

1 个答案:

答案 0 :(得分:0)

好的,来自http://pastebin.com/Vc8tUvpH的您的课程MyModel包含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;
}