I hopefully have a simple question I just cannot get anything I try to work.
Basically I am looking for a way to simply count the yes’s in each column where user level = a number and by username = a user name in the past week starting on monday. Also for a way to total the amounts in the amounttot column.
My SQL Database is set up like below:
DB Name: 1_1 Table: form_2
Sample of data in DB
username userlevel inspect signatu claimnum amounttot timestamp
-------- --------- ------- ------- -------- --------- ---------
BobS 7 yes yes kj98739 5388.00 2011-10-15 16:39:20
SteveN 8 yes no kj76739 5000.00 2011-10-15 15:29:00
TimK 7 no yes kj98734 6000.00 2011-10-15 14:35:06
How I have it list all data per team, I just need to get totals below this print out in a completely different table I can just place below it., how can I get this to only show the last weeks data starting on a monday:
<?php
$con = mysql_connect("localhost","1_1","XXXXXXXXXXXXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("1_1", $con);
$result = mysql_query("SELECT * FROM form_2 WHERE userlevel = '5' ORDER BY timestamp DESC");
echo "<table border='1'>
<tr>
<th><font size='1'>Name</th>
<th><font size='1'>Latitude</th>
<th><font size='1'>Longatude</th>
<th><font size='1'>Inspect</th>
<th><font size='1'>Sig</th>
<th><font size='1'>Phone #</th>
<th><font size='1'>Insur</th>
<th><font size='1'>Claim</th>
<th><font size='1'>Appr</th>
<th><font size='1'>AdjusApp</th>
<th><font size='1'>Check</th>
<th><font size='1'>Amount</th>
<th><font size='1'>Time</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><font size='1'>" . $row['username'] . "</font></td>";
echo "<td><font size='1'>" . $row['lat'] . "</font></td>";
echo "<td><font size='1'>" . $row['longa'] . "</font></td>";
echo "<td><font size='1'>" . $row['inspect'] . "</font></td>";
echo "<td><font size='1'>" . $row['signatu'] . "</font></td>";
echo "<td><font size='1'>" . $row['gotphone'] . "</font></td>";
echo "<td><font size='1'>" . $row['hain'] . "</font></td>";
echo "<td><font size='1'>" . $row['claimnum'] . "</font></td>";
echo "<td><font size='1'>" . $row['approved'] . "</font></td>";
echo "<td><font size='1'>" . $row['adjustapprov'] . "</font></td>";
echo "<td><font size='1'>" . $row['checkcollec'] . "</font></td>";
echo "<td><font size='1'>" . $row['amounttot'] . "</font></td>";
echo "<td><font size='1'>" . $row['timestamp'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Any help would be greatly appreciated. Thank you.
Here is a suggestion:
The ‘x’ and ‘y’ need to be the timestamps delimiting the query – they can be supplied by PHP or looked up directly in MySQL.
Edit: fixed query, thanks to @knittl.