如何根据Codeigniter中的Recno移至下一个条目

时间:2018-12-05 06:15:21

标签: php codeigniter paging

如果用户单击第一个按钮,则我有四个按钮,最后一个,上一个和下一个按钮,那么必须显示recno的最小值,如果用户单击next,则没有下一个最小值。 。我的问题是我没有收到任何错误,并且我有四个按钮。..(首先,下一个,上一个,最后一个)没有一个按钮在工作。.根据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>

它打印的是正确的值,首先我使用print_r(exp)检查了它。我的问题是如何在链接(href链接)中显示它

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>