php - How can I successfully implement a "Remember This Action" routine? -
i having difficult time getting started task.
i have 2 forms on same page.
the first form provides search box users enter 1 of several search filters address, zip code, streets, landlots, state name.
if search produces several results, user can click on advanced search link.
this advanced search contains several checkboxes allow users check 1 or more boxes narrow search results.
this works great.
the issue give user ability "save" search results perhaps using cookies next time user loads page, search result s/he saved last time become his/her default search page until change or until remove cookies wipes out last action.
this more remembering user's last action when s/he searched page last time.
my thinking far, first of all, store sql query in session variable in php code.
then, when user clicks on "remember action" button going create", have php code save session variable value in cookie.
in other words, this:
$tsql = "select name, feattype, minx, miny, maxx, maxy mytable order listorder, name desc"; session("lastaction") = $tsql and have "remember action" button post php page does:
cookies("lastaction") = session("lastaction") cookies("lastaction").expires = date() + 365 ' expires in 1 year finally, can provide "repeat last action" button on our pages , is
$tsql = request.cookies("lastaction") $stmt = sqlsrv_query( $conn, $tsql); one of many issues having can't beyond query:
$tsql = "select name, feattype, minx, miny, maxx, maxy mytable order listorder, name desc"; session("lastaction") = $tsql
i keep getting "invalid" error on
session("lastaction") = $tsql obviously, very, weak on php working hard come speed.
your assistance appreciated
i have made baby steps here.
i able syntactically correct:
$_session["lastaction"] = $tsql; i able set correct
setcookie('lastaction',$_session["lastaction"],time() + (86400 * 365)); // 86400 = 1 year now, equivalence of line in php?
$tsql = request.cookies("lastaction") above best stab @ don't think correct.
i trying put "remember last action" buttonn on page.
then use:
$tsql = request.cookies("lastaction")
to grab values page page.
what doing here is, basically, saving sql query cookie (user-editable data).
setcookie('lastaction',$_session["lastaction"] /*we're saving value, not session. */,time() + (86400 * 365)); // 86400 = 1 year regardless, instead of fooling around resurrecting sessions based on sessid saved in cookie, i'd recommend saving search flags cookie serialized array, , run-off-the-mill search using data when need reuse it.
basically, can do:
$saved_search = serialize($search_opts); setcookie('savedsearch',$_session["lastaction"],time() + (86400 * 365)); and reverse process,
$saved_search = $_cookie['savedsearch']; $search_opts = unserialize($saved_search); you need figure out own code snag $search_opts , how use them later run search, not see code makes part tick.
Comments
Post a Comment