如何在表格数据中移动第一个,下一个,上一个,最后一个Acno?

时间:2018-12-12 05:47:10

标签: php pagination

我的问题是,我正在使用四个数据库来保存各自的数据,现在我想先移动,下一个,上一个,最后一个。 我已经得到一个数据库数据,但是我没有得到html表数据,视图页面中仅显示数据的第一行。

enter image description here

在还款时间表中,我只显示了一行,其余的行都没有显示。

enter image description here 这是还款时间表的数据库。

    public function daybook($id = '')
    {
        $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];
    $query = $this->db->get('parmaster');    
    $data['PName']=$query->result_array();
    $data['query']=$this->User_model->viewAccMaster();
    $data['query1']=$this->User_model->viewAccMaster1();

        $first = $this->db->query('SELECT MIN(Repay_id),MIN(TAcNo) AS `first` FROM `tipup_payment` LEFT OUTER JOIN repay_schedule ON `repay_schedule`.`Repay_id` = `tipup_payment`.`TAcNo` ORDER BY TAcNo DESC LIMIT 1')->row_array();

    $firstID = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  where TAcNo='$first[first]' AND Repay_id='$first[first]'ORDER BY TAcNo ASC")->result_array();

$last = $this->db->query('SELECT MAX(Repay_id),MAX(TAcNo) AS `last` FROM tipup_payment LEFT OUTER JOIN repay_schedule ON `repay_schedule`.`Repay_id` = `tipup_payment`.`TAcNo` ORDER BY TAcNo DESC LIMIT 1')->row_array();

$lastID = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  where TAcNo='$last[last]' and Repay_id='$last[last]'  ORDER BY TAcNo")->result_array();

if(!empty($id)){
        $result = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule` WHERE TAcNo = $id and Repay_id = $id" )->row_array();
    }else{
        $result = "";
    }

    $allData = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  ORDER BY TAcNo ASC")->result_array();

            //$result = $resultQuery->result_array();

        if(!empty($id)){
            $data['currentID'] = $id;
        }else {
            $data['currentID'] = $first['first'];
        }
        $data['firstID'] = $first;
        $data['lastID'] = $last;
        $data['result'] = $result;
        $data['allData'] = $allData;
        //echo '<pre>';print_r($result);
        $this->load->view('TipUp_Loan/Open_Payment_FPNL', $data, FALSE);
    }

这是一个控制器代码...

                        <ul class="dropdown-menu dropdown-menu-right">

                            <li class="divider"></li>
                            <ul class='pagination'>
                                 <a href='<?php echo base_url().'/TipUp_Loan/daybook/'.$firstID['first']; ?>' class='button'><i class="icon-first">First</i></a><br><br>
                                <?php
                                    if($currentID != $lastID['last']){
                                        foreach ($allData as $next_key => $next_value) {
                                            //echo $next_key+1;
                                            //echo '<pre>';print_r($next_value);exit();
                                            if($currentID == $next_value['TAcNo']){
                                               $nextID = $allData[$next_key+1];

                                            }
                                        }
                                        $anchorTagNext = base_url().'/TipUp_Loan/daybook/'.$nextID['TAcNo'];
                                    }else {
                                        $anchorTagNext = '#';
                                    }
                                ?>
                                    <a href='<?php echo $anchorTagNext; ?>' class='button'><i class="icon-next">Next</i></a><br><br>
                                <?php
                                    if($currentID != $firstID['first']){
                                        foreach ($allData as $prev_key => $prev_value) {
                                            //echo '<pre>';print_r($prev_value);exit();

                                            if($currentID == $prev_value['TAcNo']){
                                                //echo $allData[$prev_key-1]['recno'];exit();
                                               $prevId = $allData[$prev_key-1];
                                            }
                                        }
                                        $anchorTagPrevious = base_url().'/TipUp_Loan/daybook/'.$prevId['TAcNo'];
                                    } else {
                                        $anchorTagPrevious = '#';
                                    }
                                ?>
                                <a href='<?php echo $anchorTagPrevious; ?>' class='button'><i class="icon-previous">Previous</i></a><br><br>
                                <a href='<?php echo base_url().'/TipUp_Loan/daybook/'.$lastID['last']; ?>' class='button'><i class="icon-last">Last</i></a><br>

<li class="divider">

                            </li>
                             </ul>

                        </ul>

这是查看页面代码。...

1 个答案:

答案 0 :(得分:0)

public function daybook($id = '')
{
    $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];
    $query = $this->db->get('parmaster');    
    $data['PName']=$query->result_array();
    $data['query']=$this->User_model->viewAccMaster();
    $data['query1']=$this->User_model->viewAccMaster1();

    $first = $this->db->query('SELECT MIN(Repay_id),MIN(TAcNo) AS `first` FROM `tipup_payment` LEFT OUTER JOIN repay_schedule ON `repay_schedule`.`Repay_id` = `tipup_payment`.`TAcNo` ORDER BY TAcNo DESC LIMIT 1')->row_array();

    $firstID = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  where TAcNo='$first[first]' AND Repay_id='$first[first]'ORDER BY TAcNo ASC")->result_array();

    $last = $this->db->query('SELECT MAX(Repay_id),MAX(TAcNo) AS `last` FROM tipup_payment LEFT OUTER JOIN repay_schedule ON `repay_schedule`.`Repay_id` = `tipup_payment`.`TAcNo` ORDER BY TAcNo DESC LIMIT 1')->row_array();

    $lastID = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  where TAcNo='$last[last]' and Repay_id='$last[last]'  ORDER BY TAcNo")->result_array();

if(!empty($id)){
    $result = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule` WHERE TAcNo = $id and Repay_id = $id" )->result_array();
}else{
    $result = "";
}

$allData = $this->db->query("SELECT * FROM `tipup_payment`,`repay_schedule`  ORDER BY TAcNo ASC")->result_array();

        //$result = $resultQuery->result_array();

    if(!empty($id)){
        $data['currentID'] = $id;
    }else {
        $data['currentID'] = $first['first'];
    }
    $data['firstID'] = $first;
    $data['lastID'] = $last;
    $data['result'] = $result;
    $data['allData'] = $allData;
    //echo '<pre>';print_r($result);exit();
    $this->load->view('TipUp_Loan/Open_Payment_FPNL', $data, FALSE);
}

这是控制器代码。

    <?php
//echo '<pre>';print_r($result);exit();
if(!empty($result)){
foreach($result as $row){
?>
<tr>

<td ><input style="width:40px" type="text" class="form-control" name="Sno[]" value="<?php echo $row['Sno']; ?>" id="Sno" readonly></td>

<td><input style="width:100px" type="text" class="form-control" name="Date[]" value="<?php echo $row['Date']; ?>" id="Date" readonly></td>

<td> <input style="width:70px" type="text" class="form-control" name="Amount[]" value="<?php echo $row['Amount']; ?>" id="Amount1" readonly></td>

<td ><input style="width:80px" type="text" class="form-control" name="Bankname[]" value="<?php echo $row['BankName']; ?>" id="Bankname" readonly></td>

<td ><input style="width:80px" type="text" class="form-control" name="Chqamt[]" value="<?php echo $row['Chqamt']; ?>" id="Chqamt" readonly></td>


<td><input type="text"  style="width:100px" class="form-control" name="Payable[]"  value="<?php echo $row['Payable']; ?>" id="Payable" readonly>
</td>

<td ><input style="width:80px" type="text" class="form-control" name="Bank1[]" value="<?php echo $row['BankName1']; ?>" id="Bank1"readonly></td>

<td ><input style="width:80px" type="text" class="form-control" name="Chqamt1[]" value="<?php echo $row['Chqamt1']; ?>"id="Chqamt1"readonly></td>

<td><input type="text" style="width:100px" class="form-control" name="Payable1[]" value="<?php echo $row['Payable1']; ?>" id="Payable1" readonly>
</td>


</tr>
<?php
}
}
?>

这是一个查看页面代码。