[FX.php List] How to avoid dead ends

John Phillip Barclay jbarclay at uiuc.edu
Mon Apr 24 00:05:51 MDT 2006


 
On search pages, I like to store the search criteria and sort order in
session variables.  Something like this:

$_SESSION['booksearchpage']['criteria']['title'] = 'Red';
$_SESSION['booksearchpage']['criteria']['author'] = 'Bill';
$_SESSION['booksearchpage']['sorttype']['author'] = 'ascend';
$_SESSION['booksearchpage']['sortorder']['author'] = '0';
$_SESSION['booksearchpage']['sorttype']['cost'] = 'ascend';
$_SESSION['booksearchpage']['sortorder']['cost'] = '1';

Such that when they return, I can perform the same search and sort
however they return to the page without retaining it in the url or
making them repost.  Of course this is useless if you want the user to
return to the default search and sort.

If the data isn't changing by the user or other events before they
return, you can always save the recordset in the session variable.

Below is a sort order function.  I have a similar one for search.  I
like the book PHP and MySQL for code design that goes beyond the initial
PHP syntax and language structure.

John Barclay

function
parsesort(&$sortkeys,&$blnsortchange,&$sortorder,&$sortsmarty,$debug) {

	$sortfieldnames =
array('session_date','cstatus','call_status','language_name','staff_name
');	
		
	if( $_SESSION['interpretersessionsortkeys']) {
		$sortkeys = $_SESSION['interpretersessionsortkeys'];  //
fieldname => order
		$sortorder =  $_SESSION['interpretersessionsortorder'];
// 0 based array of fields being sorted on
		}
	else {  //defaults
		$sortkeys =
array('session_date'=>'ascend',"cstatus"=>'ascend');
		$sortorder = array('session_date',"cstatus");
		}
	if ($_GET['addsort']) {
		$blnsortchange = true;
		$newsortfield = $_GET['addsort'];
		if ($sortorder ) {
			$i=0;
			foreach ($sortorder as $fieldname) {  // remove
in stack if it exists
				if ($newsortfield == $fieldname) { 
					unset($sortorder[$i]);  
					}
				 $i++; 
				 }
			array_unshift($sortorder,$newsortfield);
			if (count($sortorder) > 3) {  // only sort on
two fields at a time.
				unset($sortkeys[$sortorder[3]]);
				array_pop($sortorder);
				}
			if (empty($sortkeys[$newsortfield]))
{$sortkeys[$newsortfield] = 'ascend';}
			elseif ($sortkeys[$newsortfield] == 'ascend')
{$sortkeys[$newsortfield] = 'descend';}
			else {$sortkeys[$newsortfield] = 'ascend';}
			}
		}
	else {
		$blnsortchange = false;
		}
	
	foreach ($sortfieldnames as $sortfieldname) {
		if($sortkeys[$sortfieldname]) {
			$sortsmarty[$sortfieldname]['style'] = '
class="' . $sortkeys[$sortfieldname] . '" ';
			$sortsmarty[$sortfieldname]['image']  = 
				' <img src="/images/sort' .
$sortkeys[$sortfieldname] . '.gif" alt="sort ' .
$sortkeys[$sortfieldname].'" /> ';
			}
		}


	if ($debug) {print "<h2>sort keys6</h2>" . '<pre>';
print_r($sortkeys); print '</pre>';}
	if ($debug) {print "<h2>sort order</h2>" . '<pre>';
print_r($sortorder); print '</pre>';}	

	
	$_SESSION['interpretersessionsortkeys'] = $sortkeys;  //
fieldname => order
	$_SESSION['interpretersessionsortorder'] =	$sortorder; 
		
		
	}

--------------------------------------------
John Barclay  




-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Jonathan
Schwartz
Sent: Monday, April 24, 2006 12:44 AM
To: FX.php Discussion List
Subject: [FX.php List] How to avoid dead ends

Hi folks,

With all the fx.php examples and training resources available, I'm
starting to get the hang of this beast. ;-)

However, I'm trying to figure out how to deal with this challenge: 
Once a user has traveled down this common path....
	1) Search
	2) DisplayFound List
	3) Next>>Next>>Etc.
	4) View Detail
	5)Edit Record>>>Edit Response

...what is the best way to get back to the original found list (Step
2) to allow the user to continue the record review? Right now, I have a
dead end at the end of step 5.  Hitting the back button a handful of
time probably is not the best solution. I suppose that I could include
the original search form and require the user to recreate the search.
That's not good either.

Common sense tells me that the query could be saved in variable
somewhere, along with the id of the last viewed record.  A button or a
redirect after the edit response should get the user back.

Or.....not.

Any wisdom on this one?

Thanks for the help.

Jonathan



-- 

Jonathan Schwartz
Schwartz & Company
817 Marin Drive
Mill Valley, CA 94941
Phone: 415-381-1852
jonathan at eschwartz.com - http://www.eschwartz.com

_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list


More information about the FX.php_List mailing list