Session Variables revisited...

I have a DWMX generated page that enables dynamic sorting of the column names: ie:

<a href="<?Php echo ($tfm_orderbyURL); ?>AppName">Application Name</a>
<a href="<?Php echo ($tfm_orderbyURL); ?>Class_Code">Class Code</a>
etc...

That all works fine...I also have the ability to select the number of records per page to be displayed:
Records per page to be displayed: <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=25">25</a>
| <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=50">50</a>
etc...

That all works fine..

My challenge is: if the user wants to resort the # of records or the field name / columns it negates the previous selection. Make sense?

What i am trying to figure out is how to "cache" a user's choice...ie: Sort by Application Name...then show 50 records per screen while still sorting by Application Name.

I found this earlier snippet of code (modified for this scenario) I'm wondering how / if it would work:

<?
 if ( strlen(trim($_SESSION['sort'])) <= 0){
  $_SESSION['appname']=$HTTP_POST_VARS['appname'];
  $_SESSION['maxRows_Recordset1']=$HTTP_POST_VARS['maxRows_Recordset1'];
}
?>
-
-
-
<a href="file.php">Click This</a><? echo $_SESSION['sort']; ?>

Please forgive my feeble attempt at the aforementioned example. I'm trying to make sense of this :)

Any suggestions...Thanks

-Neils
nriddockAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lozlozCommented:
hi,

that alone won't work - all it does is to stick the choices into a session which is carried across pages (although you will need session_start(); right at the top of your script which i don't know if you have or not). so now you're storying the data you need to include it in the sorting logic. also if you're using $_SESSION, the $HTTP_POST_VARS variable should really become $_POST for both those instances. i think it'd be easier to help further if you could provide the code for the entire page

cheers,

loz
0
nriddockAuthor Commented:
Here goes:

<?php
//initialize the session
session_start();

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  session_unregister('MM_Username');
  session_unregister('MM_UserGroup');
      
  $logoutGoTo = "http://intranet";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php require_once('Connections/local_coverage.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$self=$_SERVER['PHP_SELF'];
$tfm_orderby =(!isset($HTTP_GET_VARS["tfm_orderby"]))?"AppName":$HTTP_GET_VARS["tfm_orderby"];
$tfm_order =(!isset($HTTP_GET_VARS["tfm_order"]))?"ASC":$HTTP_GET_VARS["tfm_order"];
$sql_orderby = " " .$tfm_orderby." ".$tfm_order;
?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$SSAdv_colors1 = array("#CCCCCC","#CCCCCC");
$SSAdv_k1 = 0;
$SSAdv_m1 = 0;
$SSAdv_change_every1 = 1;

if (isset($_GET['maxRows_Recordset1']))  $maxRows_Recordset1 = $_GET['maxRows_Recordset1'];
else $maxRows_Recordset1 = 50;

$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$sqlorderby_Recordset1 = "AppName";
if (isset($sql_orderby)) {
  $sqlorderby_Recordset1 = (get_magic_quotes_gpc()) ? $sql_orderby : addslashes($sql_orderby);
}
mysql_select_db($database_local_coverage, $local_coverage);
$query_Recordset1 = sprintf("SELECT * FROM projects ORDER BY %s", $sqlorderby_Recordset1);

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $local_coverage) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . implode("&", $newParams);
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . implode("&", $newParams);
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<?php
//sort column headers for Recordset1
$tfm_saveParams = explode(",","");
$tfm_keepParams = "";
if($tfm_order == "ASC") {
      $tfm_order = "DESC";
}else{
      $tfm_order = "ASC";
};
while (list($key,$val) = each($tfm_saveParams)) {
      if(isset($HTTP_GET_VARS[$val]))$tfm_keepParams .= ($val)."=".urlencode($HTTP_GET_VARS[$val])."&";      
      if(isset($HTTP_POST_VARS[$val]))$tfm_keepParams .= ($val)."=".urlencode($HTTP_POST_VARS[$val])."&";
}
$tfm_orderbyURL = $HTTP_SERVER_VARS["PHP_SELF"]."?".$tfm_keepParams."tfm_order=".$tfm_order."&tfm_orderby=";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="coverage_styles.css" rel="stylesheet" type="text/css">
</head>


<body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table width="614" border="0" align="left">
  <tr>
    <td width="1800" colspan="3"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Records
          per page to be displayed: <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=25"><font color="#FF0000">25</font></a> | <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=50"><font color="#FF0000">50</font></a><font color="#FF0000"> <font color="#000000">|</font> <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=100"><font color="#FF0000">100</font></a><font color="#FF0000"><font color="#000000"> |</font> <a href="<?php echo printf($currentPage); ?>?maxRows_Recordset1=5000"><font color="#FF0000">All</font></a></font></font></font></div>
    </td>
  </tr>
</table>
<br>
<br>
<br>
<table width="614" border="0">
  <tr>
    <td><table width="614" border="0" align="left" cellpadding="0" cellspacing="2" class="contentAreaBodyText">
      <tr bgcolor="#000000">
        <td align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>AppName">Application
                Name</a></font></strong></td>
        <td width="67" align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>Class_Code">IRM/BCP<br>
      Class</a></font></strong></td>
        <td width="84" align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>VerMgmt">Version
                Mgmt</a></font></strong></td>
        <td width="87" align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>ChgMgmt">Change
                Mgmt</a></font></strong></td>
        <td width="78" align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>SysTest">System
                Test</a></font></strong></td>
        <td width="84" align="center"><strong><font color="#FFFFCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<?Php echo ($tfm_orderbyURL); ?>ERMProcComp">Release      Mgmt</a></font></strong></td>
      </tr>
      <?php do { ?>
      <tr bordercolor="1" bgcolor="<?php
if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){
$SSAdv_k1++;
}
print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)];
$SSAdv_m1++;
?>" class="contentAreaBodyText">
        <td width="205" align="center"><div align="left"><a href="coverage_detail.php?recordID=<?php echo $row_Recordset1['CM_ID']; ?>"><font color="#000000"><?php echo $row_Recordset1['AppName']; ?></font></a></div>
        </td>
        <td align="center"><div align="center"><?php echo $row_Recordset1['IRMBCPClass']; ?></div>
        </td>
        <td width="84" align="center" bgcolor=<?php echo $row_Recordset1['VerMgmt']; ?>><span class=contentAreaBodyText<?php echo $row_Recordset1['VerMgmt']; ?>><?php echo $row_Recordset1['VerMgmt']; ?></span></td>
        <td width="87" align="center" bgcolor=<?php echo $row_Recordset1['ChgMgmt']; ?>><span class=contentAreaBodyText<?php echo $row_Recordset1['ChgMgmt']; ?>><?php echo $row_Recordset1['ChgMgmt']; ?></span></td>
        <td width="78" align="center" bgcolor=<?php echo $row_Recordset1['SysTest']; ?>><span class=contentAreaBodyText<?php echo $row_Recordset1['SysTest']; ?>><?php echo $row_Recordset1['SysTest']; ?></span></td>
        <td width="84" align="center" bgcolor=<?php echo $row_Recordset1['ERMProcComp']; ?>><span class=contentAreaBodyText<?php echo $row_Recordset1['ERMProcComp']; ?>><?php echo $row_Recordset1['ERMProcComp']; ?></span></td>
      </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table></td>
  </tr>
</table>
<br>
<br>
<br>


</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
0
aolXFTCommented:
use array_merge();


$user_selection = array_merge($_SESSION, $_POST, $_GET);

Then $user_selection['whatever']  will be $_GET['whatever'] , $_POST['whatever'], or $_SESSION['whatever'](_get if it exists, or if not _post. If neither exist it will use _session)

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.