Topic: move to next row/previous row

Hi all,i'm trying to create backend for order and order details with move to next/previous order details..I show all of the orders in one page and link to details page based on order number.I can't figure out how to create go to next/prev details page which is based on order number..What should i do to create it?Thanks alot guys.. Here are some of my codes...

model/MDetail.php

function getDetail($id)
    {
        $data = array();
        $options = array('no_order' => id_clean($id));
        $Q = $this->db->getwhere('order_detail',$options);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
            //$data = $Q->row_array();
        }
        $Q->free_result();    
        return $data;
    }

model/MOrder.php

function getOrder($no)
    {
        $data = array();
        $options = array('id' => id_clean($no));
        $Q = $this->db->getwhere('order',$options,1);
        if ($Q->num_rows() > 0)
        {
            $data = $Q->row_array();
        }
        $Q->free_result();    
        return $data;
    }

controller/order.php

function detail($id)
    {
    //$this->benchmark->mark('query_start');
    
    $data['title'] = "Order detail";
    $data['main'] = 'admin/order_detail';
    $data['order'] = $this->MOrder->getOrder($id);
    $data['detail']= $this->MDetail->getDetail($id);   
    if (!count($data['detail']))
    {
    redirect('admin/order/index','refresh');
    }
    $this->load->vars($data);
    $this->load->view('dashboard');
    }    

Last edited by Handoyo (2009-10-23 04:28:24)

Re: move to next row/previous row

Handoyo:

Maybe I'm missing something but if you are viewing the details of a particular order and want to create next/prev links, then since you have the order number already in the URL couldn't you just simply use that to help create two links where next is the current order number in the URL +1 and the previous is the current order number in the URL -1?

So let's say the URL is as follows:

http://example.com/order/detail/3

then the next link would be: http://example.com/order/detail/4
and the previous link would be: http://example.com/order/detail/2

Once you click on those links they'd run the code that's in the detail action, thus giving you the details of particular order you just clicked on.

The only other thing you'd need to check is that you're not already at the first or last order and if you are then disable the relevant link.

Hope that makes sense.

Exercise your faith!

Re: move to next row/previous row

Thanks Yannick.I got it working already.I got help from the codeigniter site.. ^_^

At the moment i got another problem..I'm intending to create the way virtuemart handle order..For example if i update the status of the order,it will show the modified date without refreshing the page..If you don't mind,you can take a look at my testing site..

7com.cphoster.com/login

username :admin
password : admin

The problem was at the order page..Thanks a lot Yannick.. ^_^ God bless you..