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

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?

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:
echo '<pre>';
   echo '</pre>';
edit: spelling and added print_r(...)

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

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:

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

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.

I also did the following after querying the database:
echo '<pre>';
   echo '</pre>';

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

    [QUERY_STRING] => /site/project_list
    [REQUEST_URI] => /site/project_list

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.

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

good points from both of you. It's given me something to think about. thank you. Smile

Theme © iAndrew 2016 - Forum software by © MyBB