Page 1 of 1
Back Button
Posted: Thu Dec 02, 2004 1:56 pm
by queen
Hi
I am going to appologize now if I incorrectly post this. First timer.
I am relatively new to PHP code. I finish school in May and I am currently working for a company part-time as a programmer. They use PHP for running the reports they need. They also use MySQL as the server database for the information gathered to fill reports. I have been asked to code the "Back" Button or even create a Previous button on the report that allows the ability to go back to the previous page of a long list of items. Which is what the "back" button currently does now. No problem there. The catch is they want the "Back" button to return them to the previous page as well as to the item the just looked at the data for so they can move on to the next line items information without loosing track of the one they just look at. Does anyone have any suggestions. I would appreciate it very much.
Here is an example of the infor mation in the report. Currently when the user clicks on the batch number (34799 ...33632) the user can go to that batch numbers information. The user wants the ability to hit the "Back" button after looking that info and the selection highlight the item they just looked at so all they have to do is arrow down to the next tem. (which in this case the next item would be 34778).
--------------------------------------------------------------------------------
34799 1V 5654 07/01/04 17:58 2,205 47 (16/20/60) 31 11 0.88 3%
34778 1V 5654 07/01/04 16:49 2,205 47 (16/20/60) 31 10 0.86 -10%
33632 1V 3640 04/01/04 20:35 3,307 22 (16/20/60) 6 17 0.86 3%
5089 1V M77B 01/09/04 20:59 1,230 23 (16/20/60) 7 11 0.89 46%
Posted: Thu Dec 02, 2004 3:21 pm
by rehfeld
use sessions.
that way you can keep track of the last item they have looked at, and display info for it on the page that lists the other items.
you may need to instruct the browser to not cache that page, otherwise when they hit the back button they may not see the "new" version of the page.
you can do this by sending the following header on pages you do not want to be cached
Code: Select all
header('Cache-Control: no-cache');
Posted: Thu Dec 02, 2004 3:32 pm
by lostboy
what about using the onclick to change the row background color and opening a new window to show the data?
Thank you
Posted: Mon Dec 06, 2004 2:04 pm
by queen
Thank you for the advice I am going to try them and see what results I get. Once again I appologise for not replying sooner. I moved on to another project and just finished it up.
Back Button cont.
Posted: Mon Dec 06, 2004 2:25 pm
by queen
Ok I tried the cache but it didn't work so I am guessing that I am not putting it in the right place. so here is the code for one report. Where would I put it?
Code: Select all
<?php
//connect to existing session
//if no existing session, send user to login page
include "verify.inc";
?>
<HTML>
<HEAD>
<TITLE>Recent Batches</TITLE>
<link rel="stylesheet" type="text/css" href="topstyle.css" />
<link rel="stylesheet" type="text/css" media="print" href="printstyle.css" />
</HEAD>
<BODY>
<div class="content">
<?php
//Generate billet type list for subtitle
if (count($_REQUESTї'billet_type_cboxes']) > 0) {
$billet_type_list = "Billet Type";
$billet_type_list .= (count($_REQUESTї'billet_type_cboxes']) > 1) ? "s: " : ": ";
foreach ($_REQUESTї'billet_type_cboxes'] as $billet_type) {
$billet_type_list .= $billet_type.", ";
}
$billet_type_list = substr($billet_type_list, 0, strlen($billet_type_list)-2);
}
else {
$billet_type_list = "All Billet Types";
}
//Generate bead type list for subtitle
if (count($_REQUESTї'bead_type_cboxes']) > 0) {
$bead_type_list = "Bead Type";
$bead_type_list .= (count($_REQUESTї'bead_type_cboxes']) > 1) ? "s: " : ": ";
foreach($_REQUESTї'bead_type_cboxes'] as $bead_type) {
$bead_type_list .= $bead_type.", ";
}
$bead_type_list = substr($bead_type_list, 0, strlen($bead_type_list)-2);
}
else {
$bead_type_list = "All Bead Types";
}
//Set report title and subtitle
$title = "Recent Batches";
$startdate = strtotime($_REQUESTї'StartDateMonth']." ".$_REQUESTї'StartDateDay'].", ".$_REQUESTї'StartDateYear']);
$enddate = strtotime($_REQUESTї'EndDateMonth']." ".$_REQUESTї'EndDateDay'].", ".$_REQUESTї'EndDateYear']);
$subtitle = date("F j, Y", $startdate) . " - " . date("F j, Y", $enddate);
$subtitle .= "<br>".$billet_type_list;
$subtitle .= "<br>".$bead_type_list;
//Add one day to end date
$enddate = mktime (date('H',$enddate),date('i',$enddate),date('s',$enddate),date('n',$enddate),date('j',$enddate)+1,date('Y',$enddate));
//Show header graphic and report title
include "header.inc";
//Connect to server specified in include file and database specified by session variable
include "connect.inc";
//Build billet type criteria
if (count($_REQUESTї'billet_type_cboxes']) > 0) {
foreach ($_REQUESTї'billet_type_cboxes'] as $billet_type) {
$billet_type_crit .= "fldMoldBilletType = '".$billet_type."' OR ";
}
$billet_type_crit = "(".substr($billet_type_crit, 0, strlen($billet_type_crit)-4).")";
}
else {
$billet_type_crit = "(1=1)";
}
//Build bead type criteria
if (count($_REQUESTї'bead_type_cboxes']) > 0) {
foreach ($_REQUESTї'bead_type_cboxes'] as $bead_type) {
$bead_type_crit .= "tblExpansionMolding.fldBeadType = '".$bead_type."' OR ";
}
$bead_type_crit = "(".substr($bead_type_crit, 0, strlen($bead_type_crit)-4).")";
}
else {
$bead_type_crit= "(1=1)";
}
//Build date criteria (already added 1 day to end date)
$date_crit = "(fldMoldStartTimeDate >= '";
$date_crit .= date("m-d-Y", $startdate)." 00:00:00' AND fldMoldStartTimeDate <= '";
$date_crit .= date("m-d-Y", $enddate)." 00:00:00')";
//Build SQL statement
$sql = "SELECT fldSheetNumber, fldMoldBilletType, tblExpansionMolding.fldBeadType, fldMoldStartTimeDate, ";
$sql .= "fldPoundsExpanded, ";
$sql .= "DATEDIFF(hh, fldExpandEndTimeDate, COALESCE(fldMoldStartTimeDate, GETDATE())) AS fldBeadAge, ";
$sql .= "ROUND(fldMinAge * ISNULL(fldAgeMultiplier, 1), 0) AS fldMinAge, ";
$sql .= "ROUND(fldTargetAge * ISNULL(fldAgeMultiplier, 1), 0) AS fldTargetAge, ";
$sql .= "ROUND(fldMaxAge * ISNULL(fldAgeMultiplier, 1), 0) AS fldMaxAge, ";
$sql .= "DATEDIFF(hh, fldExpandEndTimeDate, COALESCE(fldMoldStartTimeDate, GETDATE())) - ROUND(fldMinAge * ISNULL(fldAgeMultiplier, 1), 0) AS fldHrsOverMin, ";
$sql .= "(SELECT COUNT(fldBilletNumber) FROM tblBillets WHERE tblBillets.fldSheetNumber = tblExpansionMolding.fldSheetNumber) AS fldNumBillets, ";
$sql .= "(SELECT AVG(fldBilletWeight / (fldBilletLength * fldBilletWidth * fldBilletDepth / 144)) FROM tblBillets WHERE tblBillets.fldSheetNumber = tblExpansionMolding.fldsheetNumber) AS fldAvgDensity, ";
$sql .= "1 - (CAST((fldPoundsExpanded + ISNULL(fldPoundsAdded, 0) - ISNULL(fldPoundsRemaining, 0)) AS DECIMAL) / (SELECT SUM(fldBilletWeight) FROM tblBillets WHERE tblBillets.fldSheetNumber = tblExpansionMolding.fldSheetNumber)) AS fldRegrindPercent ";
$sql .= "FROM tblExpansionMolding LEFT OUTER JOIN tblBilletTypes ON fldMoldBilletType = fldBilletType ";
$sql .= "LEFT OUTER JOIN tblBeadTypes ON tblExpansionMolding.fldBeadType = tblBeadTypes.fldBeadType ";
$sql .= "WHERE fldMolded = 1 AND ".$billet_type_crit." AND ".$bead_type_crit." AND ".$date_crit." ";
$sql .= "ORDER BY fldMoldStartTimeDate DESC";
//Execute query
$result = mssql_query($sql, $db);
//Get data row
if ($datarow = mssql_fetch_array($result)) {
?>
<table class="detail">
<tr class="headrow"><!-- Header row -->
<td class="headlabel">Sheet</td>
<td class="headlabel">Type</td>
<td class="headlabel">Bead</td>
<td class="headlabel">Date/Time</td>
<td class="headlabel">Lbs.</td>
<td class="headlabel">Age (Min/Tgt/Max)</td>
<td class="headlabel" style="{padding-right:0px}">Hrs. Over Min.</td>
<td class="headlabel" style="{padding-right:10px}">Num. Billets</td>
<td class="headlabel">Avg. Dens.</td>
<td class="headlabel" style="{padding-right:10px}">Regrind %</td>
</tr>
<?php
while ($datarow) {
?>
<tr class="detailrow"><!-- Data row -->
<td class="detail"><a href="batch.php?BatchNum=<?= $datarowї'fldSheetNumber'] ?>"><?= $datarowї'fldSheetNumber'] ?></a></td>
<td class="detail"><?= $datarowї'fldMoldBilletType'] ?></td>
<td class="detail"><?= $datarowї'fldBeadType'] ?></td>
<td class="detail"><?= str_replace(" ", " ", date("m/d/y H:i", strtotime($datarowї'fldMoldStartTimeDate']))) ?></td>
<td class="detail"><?= number_format($datarowї'fldPoundsExpanded']) ?></td>
<td class="detail"><?= number_format($datarowї'fldBeadAge'])." (".number_format($datarowї'fldMinAge'])."/".number_format($datarowї'fldTargetAge'])."/".number_format($datarowї'fldMaxAge']).")" ?></td>
<td class="detail"><?= number_format($datarowї'fldHrsOverMin']) ?></td>
<td class="detail"><?= number_format($datarowї'fldNumBillets']) ?></td>
<td class="detail"><?= number_format($datarowї'fldAvgDensity'], 2) ?></td>
<td class="detail"><?= number_format(100 * $datarowї'fldRegrindPercent'], 0)."%" ?></td>
</tr>
<?php
//fetch next row
$datarow = mssql_fetch_array($result);
}
echo "</table>";
}
//if no row
else {
echo "No batches found.";
}
?>
</div>
</BODY>
</HTML>
Posted: Mon Dec 06, 2004 2:59 pm
by timvw
Meaby that the idea of a "program stack" can inspire you:
http://www.tonymarston.net/php-mysql/ba ... blues.html
Thanks again
Posted: Fri Dec 10, 2004 3:18 pm
by queen
thank you for your help but I guess i am just not understanding. I have tried everything that was mention with no luck.

I think that the onclick route would be best for me but I do not know where to place the code. Nor do I know where. This is the first time I have confronted PHP and or HTML code that is next semester in school for me. Any suggestion as to go about this would be wonderful?
Posted: Fri Dec 10, 2004 3:26 pm
by Joe
I have not read to much into this post but from what I gather you could try:
Code: Select all
onclick="javascript:history.back()"
Posted: Fri Dec 10, 2004 3:33 pm
by lostboy
Code: Select all
<script language='javascript'>
fuction myOnClick(itemNumber)
{
window.open("mydata.php?id="+itemNumber, 'Data_Window',їheight, width, toolbar, statusbar, etc]);
}
<tr onClick="this.background.color='orange';"><td><a href="#" onClick='myOnClick(<?=$rowї'id']?>);">Some text link</a></td></tr>
Posted: Tue Dec 14, 2004 12:54 pm
by queen
Thanks everyone for your advice, but I am just not getting it I have tried everything that has been suggested but to no avail it still does not work correctly. I even went out to other websites that I know do what I am looking for to view the source code and still can't find what I am looking for. This is a real drag. But I am just not sure what to do know.
Posted: Tue Dec 14, 2004 12:55 pm
by lostboy
try showing a little code around the problem areas...it just not that complex that we can't sort it out a few minutes