Welcome Guest, Not a member yet? Register   Sign In
Show data on page after page refresh
#1

[eluser]jshultz[/eluser]
I've got a page where I can query the db and it will spill out the results from the database.

I can then delete certain rows as I want, which causes a page refresh.

Of course, when the page refreshes, the results from the database are gone. any idea on how i can change this behavior or work around it?
#2

[eluser]John_Betong[/eluser]
 
I have recently written some code for a similar problem. My approach was to use the _SERVER['LAST_REQUEST'] and/or store $_SESSION['last_page'] = $this->uri->uri_string(). After your delete code has finished then call redirect($_SESSION['last_page']); which will re-build the page without the deleted items.
 
 
To see what else is available use this code:
Code:
echo '<pre>';
     print_r($_SERVER);
   echo '</pre>';
&nbsp;
&nbsp;
&nbsp;
edit: spelling and added print_r(...)
#3

[eluser]bretticus[/eluser]
[quote author="jshultz" date="1254803471"]
Of course, when the page refreshes, the results from the database are gone. any idea on how i can change this behavior or work around it?[/quote]

It really depends on how you refresh the page. Are you doing this with javascript (ajax?) Are you using a search string in the URL? Are you posting a search string to a form handler?
#4

[eluser]jshultz[/eluser]
the page is populate via a select box and post method. the url for the page just looks like domain.com/site/project_list

I attempted to do the server last page idea:

Code:
function deleteTask() {
        $_SESSION['last_page'] = $this->uri->uri_string();
        $taskid = (string)$this->input->post('taskid', TRUE);
        $this->Project_model->delete_task($taskid);
        redirect($_SESSION['last_page']);
    }

but that didn't work. I got an error in firefox saying:

The page isn't redirecting properly


Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
#5

[eluser]jshultz[/eluser]
I also did the following after querying the database:
Code:
&lt;?php
echo '<pre>';
     print_r($_SERVER);
   echo '</pre>';
   ?&gt;

and here's the items i thought you would find important:

Code:
[REQUEST_METHOD] => POST
    [QUERY_STRING] => /site/project_list
    [REQUEST_URI] => /site/project_list
#6

[eluser]bretticus[/eluser]
Off the top of my head, I would either:

1. Make the delete link submit the entire page as one form, since you would be able to keep state with the drop down menu values.

2. Make the delete link an ajax transaction. Remove the listing row from the DOM on callback.
#7

[eluser]BrianDHall[/eluser]
I would permit the delete page an extra parameter which is the value of select box you want to return to after delete, then permit the same extra parameter on your search page.

If this extra parameter is set when a function is called, ignore the POST value and use the parameter instead.

So you might have mysite.com/controller/search now that POSTs to itself, but allow it to be mysite.com/controller/search/selectboxvalue - the delete function then takes the selectboxvalue and uses it to build the redirect() link back to your search page.

Thats how I'd do it, even though doing it with AJAX is way more l33t, I consider it one more manual to consult Wink
#8

[eluser]jshultz[/eluser]
good points from both of you. It's given me something to think about. thank you. Smile




Theme © iAndrew 2016 - Forum software by © MyBB