Forum Moderators: coopster

Message Too Old, No Replies

Totaling elements in an array

         

Shaman13

8:41 pm on Dec 27, 2004 (gmt 0)

10+ Year Member



Happy Holidays Everyone! I'm stumped! Nothing new! Hoping that someone can help me figure out how to create an array or a series of arrays generated by my query that will group the outputted array data by day. The following code generates a report based upon three variables entered by the user, a staff number STAFF and two dates TIDATEA AND TIDATEB. Currently the following code generates a lenghtly list of records for dates between the two dates entered for the staff person selected. What I would like to do is break the resultant array up into distinct dates with a total for each date TIDATE beneath the array. This would allow the user to quickly review the data day by day to check the amount of time they logged for any given day. The following is the code I am currently using which generates an extremely long list.

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Time Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
td,body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>
<body bgcolor="white">
<?php
//include global file¦¦ establishes connection to database
include ('global.php');

?>

<?php
// create short variable names
//$TIDATE=$HTTP_POST_VARS['TIDATE'];
$TIDATEA=date("Y/m/d");

//$TIDATEB=date(" m/j/Y");
$TIDATE=date("Y/m/d");

$TIDATEA= trim($TIDATEA);
//$TIDATEB= trim($TIDATEB);

if (!$TIDATE ¦¦!$TIDATEA)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$TIDATE = addslashes($TIDATE);
$TIDATEA = addslashes($TIDATEA);
//$TIDATEB = addslashes($TIDATEB);

////////////////////////////////////////////

$query = "SELECT ttime.TIDATE,ttime.TTIME, ttime.REASON, _clientsw_cases.CLNAME, ttime.TIMEACTIVITY, ttime.CASEACTIVITY, ttime.SNUM, ttime.FUNDSNUM FROM ttime left join _clientsw_cases ON ttime.CASENUM=_clientsw_cases.CASENUM WHERE ttime.SNUM = '".$_SESSION['STAFF']."' AND (TIDATE BETWEEN '%".$_SESSION['TIDATEA']."%' AND '%".$_SESSION['TIDATEB']."%')ORDER BY TIDATE ASC "

//"SELECT TIDATE,TTIME,REASON,CASENUM,NONCASE,TIMEACTIVITY,SNUM FROM ttime where SNUM = '".$_SESSION['SNUM']."' AND TIDATE = '".$TIDATE."'"
or die("SELECT Error: ".mysql_error());

$result = mysql_query($query);
?>
<A HREF="javascript:window.print()">Click to Print This Page</A><br>
<A HREF="staff_time.php">Return to Time Records Query.</A>
<p>
<b>
<table border="1" cellpadding="0" cellspacing="0" bgcolor="#99FF99">
<tr>
<td>
<b>
<?php
echo "Time Records for staff number " .$_SESSION['STAFF'];?>
<br>
<?php
echo "For the period " .$_SESSION['TIDATEA'];?>
<?php
echo " through " .$_SESSION['TIDATEB'];?>
</b>
</td>
</tr>
</table>
<br>

<b>

<?php
echo "Printed on";
print date(" m/j/Y");
?>
<br><br><b\>

<center>
<font face="Times New Roman" size="3">
<?php
print("<TABLE BORDER=1,width=725,body bgcolor=#FFFFFF><TR>");
print("<TH>Time Date</<TH>");
print("<TH>Amount of Time</<TH></TR>");
print("<TH>Reason</<TH>");
print("<TH>Client</<TH></TR>");
print("<TH>Activity</<TH></TR>");
print("<TH>Case Act.</<TH></TR>");
print("<TH>Advocate</<TH></TR>");
print("<TH>Funds</<TH></TR>");

for ($index = 0; $index < 5; $index++)

$j=true;
while ($row = mysql_fetch_row($result))
{
if($j)
$j=false;
else
$j=true;
echo "<tr>";

for ($i=0;$i<mysql_num_fields($result);$i++){
if ($j){
echo "<td bgcolor=\"#CCFF99\">";
}
if (!$j){
echo "<td bgcolor=\"#FFFFCC\">";
}
echo $row[$i];

echo"</td>";
}
}
echo "</table></center>
</div>
";
mysql_close();
?>

</body>

[edited by: ergophobe at 10:35 pm (utc) on Dec. 27, 2004]
[edit reason] fixed sidescroll [/edit]

Salsa

5:27 pm on Dec 28, 2004 (gmt 0)

10+ Year Member



Will it help you to include a GROUB BY before your ORDER BY?

...And to get a faster response in the future, it might help to not post so much irrelevant code [webmasterworld.com]. For future reference, there is also a link to that page from the forum charter [webmasterworld.com].

I hope this helps.