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

How to move to next entries according to the recno in codeigniter

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

    $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>

它在 first、last、next、prev 中打印正确的值我使用 print_r(exp) 检查了它..我的问题是如何在 link(href links)

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

而不是

<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>

有效答案 控制器代码:

$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>