Languages :: PHP :: going back to a page and saving variables |
|||
| By: PHP newbee |
Date: 19/09/2003 00:00:00 |
Points: 500 | Status: Answered Quality : Excellent |
|
dumb title...i know. Here is an explanation of what i am trying to do: I have a page that dynamically creates form lists when the pages loads. The lists are created from tables in a mysql database. We can focus on one list for this. So, the list is created from a 'select * from table' query. When the page is first loaded I want all the items on the list pre-selected. Then when the page is *submitted* these variables from the form list go into the $_POST array. I then pull out the values from the post array and use them to alter a different sql statement where the values are concatonated into a "where blah is in (" constraint. The page finishes loading with a modified sql query for the data on the page i am trying to display. the requirements I have for the lists is this: When I load the page the first time, all the list values are pre selected. If say 2 items on the list are selected then the page is submitted, the data on the page is altered. Should the user navigate away from that page and then hit the back button to it, I want the same variables to be used to preselect those same 2 values which were previously selcted. I dont want "Warning" This page is expired" to happen. |
|||
| By: waygood | Date: 19/09/2003 07:00:00 | Type : Answer |
|
| I always use a go between page with no output to process POSTed data. It then re-directs to another page with the header function. Since there is no output from that page it doesn't get added to the history and you never re-submit. ie one.php ----------- <form action="process.php" .... . . </form> process.php --------------- <?php $_SESSION['posted']=$_POST; header("location : two.php"); exit; ?> two.php ---------- <?php print_r($_SESSION); ?> |
|||
| By: PHP newbee | Date: 19/09/2003 07:04:00 | Type : Comment |
|
| here is the code i have started to use.....everything works except for the back functionality......i know its sloppy, that will change later ;) <?php /* ---->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> ---->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> *********************************************************************************************** ************************************* L-TR/-\K ******************************************** ******* Created by Anthony Meo ******* ******* Web Based Request/Bug Tracking System ******* ******* Copyright 2003 LazyElm Designs ******* ******* ******* ******* Please keep these tags if you use this software ******* *********************************************************************************************** *********************************************************************************************** */ //Include Variable - Option File session_start(); require('ltrack-var-opt.php'); /* ---->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> ---->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> */ ?> <?PHP //query to populate issues list $query_getissue = "select * from issue"; $getissue = mysql_query($query_getissue, $bugger) or die(mysql_error()); $row_getissue = mysql_fetch_assoc($getissue); $totalRows_getissue = mysql_num_rows($getissue); if (!$query_getissue) { echo("<P>Error performing update bug table query: " . mysql_error() . "</P>"); ltrak_exit(); } //query to populat status list $query_getstatus = "select * from status"; $getstatus = mysql_query($query_getstatus, $bugger) or die(mysql_error()); $row_getstatus = mysql_fetch_assoc($getstatus); $totalRows_getstatus = mysql_num_rows($getstatus); if (!$query_getstatus) { echo("<P>Error performing update bug table query: " . mysql_error() . "</P>"); ltrak_exit(); } //query open requests if ($HTTP_GET_VARS[submit]){ print_r ($_POST[is_id]); $query_active_bugs ="SELECT b.bug_id, u.user_name, b.bug_title, UNIX_TIMESTAMP(b.bug_start_date) FROM bug b, users u, issue i, status s WHERE b.status_id = s.status_id and b.user_id = u.user_id and b.issue_id = i.issue_id and b.status_id = s.status_id and b.user_id = $_SESSION[uid] "; //add issue_id's $query_active_bugs .= "and b.issue_id IN ("; $is_id_count = count($_SESSION[aryIssueList]); $comma = 0; for ($i=0; $i <= $is_id_count; $i++){ if (($comma !=0) && $i != $is_id_count){ $query_active_bugs .=","; } $query_active_bugs .= $_SESSION[aryIssueList][$i]; $comma++; } $query_active_bugs .= ") "; //-------------------------------------------- //add status-id's $query_active_bugs .= "and b.status_id IN ("; $stat_id_count = count($_POST[stat_id]); $comma2 = 0; for ($i2=0; $i2 <= $stat_id_count; $i2++){ if (($comma2 !=0) && $i2 != $stat_id_count){ $query_active_bugs .=","; } $query_active_bugs .=$_POST[stat_id][$i2]; $comma2++; echo $_POST['stat_id[$i2]']; } $query_active_bugs .= ") "; //----------------------------------------------- $query_active_bugs .= "order by b.bug_id desc"; //View the sql on query for debugging. //echo " $query_active_bugs "; //copy post variables into $aryIssueList unset($_SESSION[aryIssueList]); for ($l = 0; $l < count($_POST[is_id]); $l++){ $_SESSION[aryIssueList][$l] = $_POST[is_id][$l]; } print_r($_SESSION[aryIssueList]); } //Else not submit else{ $_SESSION[aryListIssue] = array(); $k = 0; do { $_SESSION[aryListIssue][$k] = $row_getissue['issue_id']; $k++; } while ($row_getissue = mysql_fetch_assoc($getissue)); $rows = mysql_num_rows($getissue); if($rows > 0) { mysql_data_seek($getissue, 0); $row_getissue = mysql_fetch_assoc($getissue); } /*for ($k2=0; $k2<=$totalRows_getstatus; $k2++){ mysql_data_seek($getstatus, 0); $_POST[stat_id][$k2] = $row_getstatus['status_id']; } $rows_status = mysql_num_rows($getstatus); if($rows_status > 0) { mysql_data_seek($getstatus, 0); $row_getstatus = mysql_fetch_assoc($getstatus); }*/ $query_active_bugs ="SELECT b.bug_id, u.user_name, b.bug_title, UNIX_TIMESTAMP(b.bug_start_date) FROM bug b, users u, issue i, status s WHERE b.status_id = s.status_id and b.user_id = u.user_id and b.issue_id = i.issue_id and b.status_id in (2) and b.user_id = $_SESSION[uid] order by b.bug_id desc"; } $active_bugs = mysql_query($query_active_bugs, $bugger) or die(mysql_error()); $row_active_bugs = mysql_fetch_assoc($active_bugs); $totalRows_active_bugs = mysql_num_rows($active_bugs); ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="content.css" rel="stylesheet" type="text/css"> </head> <body> <div align="center"></div> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="50%" align="center" valign="top"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="24"> </td> <td> </td> <td><div align="center"><font size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#663366" size="3" face="Verdana, Arial, Helvetica, sans-serif">.......::.:..:::Requests:::..:.::.......</font></strong></font></div></td> <td> </td> </tr> <tr bgcolor="#6699CC"> <td width="10%" class="buglisttop"><div align="center"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Bug</font></strong></div> </td> <td width="10%" class="buglisttop"><div align="center"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Owner</font></strong></div> </td> <td width="60%" bgcolor="#6699CC" class="buglisttop"><div align="center"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Subject</font></strong></div> </td> <td width="20%" class="buglisttop"><div align="center"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Start.Date</font></strong></div> </td> </tr> <?php //Loop to display open requests do { ?> <tr align="center" valign="middle" bgcolor="<?php echo requestBG(checkEdited($row_active_bugs['bug_id']));?>" onclick="window.location='bugviewer.php?id=<?php echo $row_active_bugs[bug_id]; ?>';" onmouseover="this.style.cursor='hand';" class="linkmodi"> <td height="26" bgcolor="<?php echo requestBG(checkEdited($row_active_bugs['bug_id']));?>" class="buglistbugleft"> <div align="center"> <?php echo "$row_active_bugs[bug_id]"; ?> </div> </td> <td height="26" class="bugbotline"><div align="center"> <?php echo "$row_active_bugs[user_name]"; ?> </div> </td> <td height="26" class="bugbotline"> <div align="left"> <?php echo $row_active_bugs[bug_title]; ?> </div> </td> <td height="26" bgcolor = "<?php echo ageColor($row_active_bugs['UNIX_TIMESTAMP(b.bug_start_date)']); ?>" class="buglistbugright"> <div align="center"> <? echo formatDateList($row_active_bugs['UNIX_TIMESTAMP(b.bug_start_date)']); ?> </div> </td> </tr> <?php } while ($row_active_bugs = mysql_fetch_assoc($active_bugs)); ?> </table></td> <td width="25%" align="center" valign="top"><table width="95%" border="0" align="right" cellpadding="0" cellspacing="0"> <tr> <td>Filters</td> </tr> <tr> <td> <form name="form1" method="post" action="<?php echo $_PHPSELF ?>"> <?php echo "<select name='is_id[]' size='$totalRows_getissue' multiple class ='textboxmodi'>"; //populate issue drop down do { if (in_array($row_getissue[issue_id], $_SESSION[aryIssueList])) { echo "<option value='$row_getissue[issue_id]' selected>$row_getissue[issue_name]</option>"; } else{ echo "<option value='$row_getissue[issue_id]'>$row_getissue[issue_name]</option>"; } } while ($row_getissue = mysql_fetch_assoc($getissue)); $rows = mysql_num_rows($getissue); if($rows > 0) { mysql_data_seek($getissue, 0); $row_getissue = mysql_fetch_assoc($getissue); } ?> </select> <?php echo "<select name='stat_id[]' size='$totalRows_getissue' multiple class ='textboxmodi'>"; //populate issue drop down do { if (in_array($row_getstatus[status_id], $_POST[stat_id])) { echo "<option value='$row_getstatus[status_id]' selected>$row_getstatus[status_name]</option>"; } else{ echo "<option value='$row_getstatus[status_id]'>$row_getstatus[status_name]</option>"; } } while ($row_getstatus = mysql_fetch_assoc($getstatus)); $rows = mysql_num_rows($getstatus); if($rows > 0) { mysql_data_seek($getstatus, 0); $row_getstatus = mysql_fetch_assoc($getstatus); } ?> <!--<input type="submit" name="Submit" value="Submit" class="buttonmodi"> --> </p> </form></td> </tr> </table> <a href="buglist2.php?submit=1">Submit </a> </td> </tr> </table> <?php //ageColor($row_active_bugs['UNIX_TIMESTAMP(b.bug_start_date)']); ?> </body> </html> <?php //clear memory of queries mysql_free_result($active_bugs); ltrak_exit($bugger); ?> |
|||
| By: VGR | Date: 19/09/2003 16:15:00 | Type : Comment |
|
| this : $is_id_count = count($_SESSION[aryIssueList]); $comma = 0; for ($i=0; $i <= $is_id_count; $i++){ if (($comma !=0) && $i != $is_id_count){ $query_active_bugs .=","; } $query_active_bugs .= $_SESSION[aryIssueList][$i]; $comma++; } can be easily converted to brutal force : for ($i=0; $i <= $is_id_count; $i++) $query_active_bugs .= "{$_SESSION[aryIssueList][$i]},"; $query_active_bugs=substr($query_active_bugs,0,strlen($query_active_bugs)-1); // sorry, there is no LEFT() function in PHP |
|||
| By: PHP newbee | Date: 22/09/2003 06:38:00 | Type : Comment |
|
| forgive my ignorance, but i do not know what "can be easily converted to brutal force :" means |
|||
| By: PHP newbee | Date: 22/09/2003 06:39:00 | Type : Comment |
|
| waygood...you may be onto something for me...is there a way to adapt that method when usung the $PHP_Self posting action. ? |
|||
| By: VGR | Date: 22/09/2003 06:52:00 | Type : Assist |
|
| not with PHP_SELF. But the go-between page may very well redirect to what would have been PHP_SELF :D for the "brutal force", it's explained just two lines below... I only optimized a bit the coding. |
|||
| By: waygood | Date: 22/09/2003 07:09:00 | Type : Comment |
|
| You could use PHP_SELF as long as you redirect to PHP_SELF after processing the post. BUT in order for the information to change you would need to pass some info to that page either in a session or the URL ($_GET). I am not sure about the session way though, especially if you move forward and backwards, but URL should work okay. ie if(sizeof($_POST)>0) { // process $_POST // generate some values for url eg x=1&y=2 and add them to the end of the header eg $_SERVER['PHP_SELF']."?".$url_vars); header("location : ".$_SERVER['PHP_SELF']); exit; } else { // test for $_GET variables and contruct content accordingly // show info } for VGRs comment above, you would use something like : <input name="referrer" type="hidden" value="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>" /> |
|||
| By: PHP newbee | Date: 25/09/2003 00:28:00 | Type : Comment |
|
| sorry it took so long for the points,, had to go away on emergency trip...but here they are now. All of you thanks for the help. Waygood, your middle man page did the trick, and then I went back to the page like vgr suggested. I wish i could give yall both 500 points...I have plenty to spare but i cant. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








