Welcome Guest, Not a member yet? Register   Sign In
Redirecting to the same page after edit
#1

[eluser]quest13[/eluser]
Hi, Is there any way I can redirect to the specific page after edit or delete ?

Say I have 40 records and I have 8 records per page and If I edit 32 th record, after update, I want to redirect the user to 3 page.But It is redirected to first page always by default.
#2

[eluser]tonanbarbarian[/eluser]
assuming you are using the pagination library... i have previously modified the pagination library to be able to retrieve the pagination data from the session
That way you can leave the page and come back at any time and it is still on the same page it was last time
i do the same with any search filters I might have on a list as well
#3

[eluser]quest13[/eluser]
Thanks for the response. I am using the CI library only. However, I will try with the session and come back
#4

[eluser]steve_mock[/eluser]
Related:

Jumping to the appropriate page/offset immediately after a new record is inserted?

Sounds hard. But, thanks in advance.
#5

[eluser]Dam1an[/eluser]
[quote author="steve_mock" date="1248833546"]Related:

Jumping to the appropriate page/offset immediately after a new record is inserted?

Sounds hard. But, thanks in advance.[/quote]

It's not really that hard
Once you insert a new item, you need to find out the totaly number of rows (you already do this when creating the pagination links) and divide that by however many items/page. That gives you the oage number, so just redirect to the pagination URL with that number as the last segment... make sense?
#6

[eluser]steve_mock[/eluser]
[quote author="Dam1an" date="1248834052"]... make sense?[/quote]

Perfectly. Thank you.

However... the freshly inserted record may not fall at the very end. Smile

I am sorting my tables by user-entered event date (not a timestamp) and events are created non-chronologically. So my "target" record is likely somewhere in the middle of the total count.

I reckon I could get its active record row number (after the sort) and do a little math to cough up the offset... hmmm.

-s
#7

[eluser]Dam1an[/eluser]
Ah, you like to make things a little more interesting then
Here's a little example which should point you in the right direction, except I'll be using names instead of dates, but its basically the same thing

Code:
// Insert the user and get their ID
$this->db->insert('users', array('name'=>'Damian'));
$user_id = $this->db->insert_id();

// Get all the users sorted by name
$this->db->order_by('name', 'asc');
$query = $this->db->get('users');
$users = $query->result();

// Loop through the users till we find the one with the same ID
// Need the key as well as the value so we can work out the page
foreach($users as $k=>$v) {
    if($v->id == $user_id) {
        $page = $k / ROWS_PER_PAGE;
        redirect('users/page/'.$page);
    }
}

Hopefully thats enough to get you in the right direction
#8

[eluser]steve_mock[/eluser]
Nice!

insert_id(); is the ticket. That'll come in handy all over the place.

Thank you so much, Dam1an.

-s
#9

[eluser]Dam1an[/eluser]
Your welcome Smile
Yeah insert_id is sooo useful




Theme © iAndrew 2016 - Forum software by © MyBB