如何根据codeigniter中的recno移动到下一个条目

问题描述 投票:0回答:2

我有四个按钮,第一个,最后一个,上一个和下一个按钮,如果用户单击第一个按钮,则必须显示recno的最小编号,如果用户单击下一个,则必须显示下一个的最小编号..my问题是我没有收到任何错误,我有四个按钮..(第一个,下一个,上一个,最后一个)没有一个按钮起作用..帮助我根据记录移动到下一个条目..提前致谢.... 这是我的控制器代码:

    $first = $this->db->query('SELECT MIN(recno) AS `first` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();

        $firstID = $this->db->query("SELECT * FROM `daybook`  where recno='$first[first]' ORDER BY recno ASC")->result_array();
        //$firstID = $firstIDQuery->result_array();
         $last = $this->db->query('SELECT MAX(recno) AS `last` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
        $lastID = $this->db->query("SELECT * FROM `daybook` where recno='$last[last]'  ORDER BY recno")->result_array();
        //$lastID = $lastIDQuery->result_array();

        $id = 1;
        if(!empty($id)){
       $result = $this->db->query("SELECT * FROM daybook WHERE recno = $id")->result_array();
   }
            //$result = $resultQuery->result_array();

        $data['currentID'] = $id;
        $data['firstID'] = $first;
        $data['lastID'] = $last;
        $data['result'] = $result;
        $this->load->view('BookKeeping/DayBookEntry', $data, FALSE);

这是我的查看页面:

 <ul class='pagination'>
        <a href='<?php echo base_url().'/BookKeeping/daybook/'.$firstID; ?>' class='button'>First</a><br>
        <?php
            if($currentID != $firstID){
                foreach ($result as $next_key => $next_value) {
                    if($currentID == $next_value['recno']){
                        $nextID = $result[$next_key]++;
                    }
                }}
        ?>
            <a href='<?php echo base_url().'/BookKeeping/daybook/'.$nextID['recno']; ?>' class='button'>Next</a><br>
        <?php
            if($currentID != $lastID){
                foreach ($result as $prev_key => $prev_value) {
                    if($currentID == $prev_value['recno']){
                        $prevID = $result[$prev_key]--;
                        }
}}
        ?>


            <a href='<?php echo base_url().'/BookKeeping/daybook/'.$prevID['recno']; ?>' class='button'>Previous</a><br>
        <a href='<?php echo base_url().'/BookKeeping/daybook/'.$lastID; ?>' class='button'>Last</a><br>
    </ul>

它在第一个、最后一个、下一个、上一个中打印正确的值,我使用 print_r(exp) 检查它。我的问题是如何在链接(href links)中显示它

php codeigniter pagination
2个回答
1
投票

工作答案 控制器代码:

$first = $this->db->query('SELECT MIN(recno) AS `first` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();

    $firstID = $this->db->query("SELECT * FROM `daybook`  where recno='$first[first]' ORDER BY recno ASC")->result_array();
    //$firstID = $firstIDQuery->result_array();
    $last = $this->db->query('SELECT MAX(recno) AS `last` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
    $lastID = $this->db->query("SELECT * FROM `daybook` where recno='$last[last]'  ORDER BY recno")->result_array();
    //$lastID = $lastIDQuery->result_array();

    //$id = 1;
    if(!empty($id)){
        $result = $this->db->query("SELECT * FROM daybook WHERE recno = $id")->row_array();
    }else{
        $result = "";
    }

    $allData = $this->db->query("SELECT * FROM daybook ORDER BY recno 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;

查看页面:

 <a href='<?php echo base_url().'/BookKeeping/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['recno']){
                                               $nextID = $allData[$next_key+1];

                                            }
                                        }
                                        $anchorTagNext = base_url().'/BookKeeping/daybook/'.$nextID['recno'];
                                    }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['recno']){
                                                //echo $allData[$prev_key-1]['recno'];exit();
                                               $prevId = $allData[$prev_key-1];
                                            }
                                        }
                                        $anchorTagPrevious = base_url().'/BookKeeping/daybook/'.$prevId['recno'];
                                    } else {
                                        $anchorTagPrevious = '#';
                                    }
                                ?>
                                <a href='<?php echo $anchorTagPrevious; ?>' class='button'><i class="icon-previous">Previous</i></a><br><br>
                                <a href='<?php echo base_url().'/BookKeeping/daybook/'.$lastID['last']; ?>' class='button'><i class="icon-last">Last</i></a>
</ul>

0
投票

您在所有内容上都滥用了单引号,而不是在适当的情况下使用单引号和双引号的组合,这会扰乱您正确创建的链接。

而不是

<a href='<?php echo base_url().'/BookKeeping/daybook/'.$nextID['recno']; ?>' class='button'>Next</a><br>

尝试

 <a href="<?php echo base_url('BookKeeping/daybook/'.$nextID['recno']; ?>" class="button">Next</a>
© www.soinside.com 2019 - 2024. All rights reserved.