I am implementing pagination on my php script, pagination is already
working, the result is displayed as checkboxes for users to check their
choices. my prob is if i have more than 1 page, users should be able to
choose from all 4 pages,
one solution is creating a temporal table, which can be re-created and
dropped when starting and ending the user session (table name can be
an unique_ID). Then, the checkbox selections are inserted, deleted,
etc.. with mysql_functions every time the user change every page.
And how do you suggest that the data will be kept when the user goes to
page 2?
The session will end and the temporary table will be destroyed. So this
is probably not so wise don't you think ?
Another solution is adding the ID of every selected checkbox to a
cookie or session variable in format 1,5,42,87,412... etc. Then you
can manage the selections changes by reading the array elements using
a for... when the user change every page:
$foo = array_unique($foo); // checkbox selections
if (count($foo) > 0) {
// loop through the array of selections
for ($i=0;$i<count($foo);$i++) {
// read and write the session_var to update, delete, etc..
if (eregi($foo[$i], $session_var)) { // if exists ...etc
}
//...
}
}
Cookie is a good choice although if the checkboxes are many your cookie
will grow. Your problem here is how you can maintain data between pages
in order to keep all the users options. This problem has many solutions:
cookies, sessions, memcache, database etc.
The problem that you will a mechanism that will control the data.
When the user ends, you will have a temporal table or a session
variable with all his checkboxes selected.
Oh now I get it !! by temporary table you don't really mean a temporary
table like that:
http://archive.devwebpro.com/devwebpro-39-20010817Temporary-Tables-With-MySQL.html
but a table you will not use permanently. But AFAIK changing schema is
bad practice. Why not just keep the table and use it for this use?
First method is slower but more secure. Second is speediest but it can
have more failures because are session vars or cookies. It depends of
your control errors and also the visits profile.
I wouldn't bet on that I think it depends on the case.
Hope it helps,
--
Thodoris