Hey people,
Looking for a solution to this one :
I've got a table with a unique ID, persons, dates and #shots.
I want to display the total #shots for each person last month. If however, this person has not entered any #shots in that month, the recordset should still return a row with his name, but total #shots = 0.
This is what I have so far :
<?php
$curdate = getdate();
if ($curdate['mon'] = 1) {
$lastmonth = 12;
} else {
$lastmonth = ($curdate['mon'] - 1);
}
if ($curdate['mon'] = 1) {
$lmyear = ($curdate['year'] - 1);
} else {
$lmyear = $curdate['year'];
}
mysql_select_db($database_TIR_AVG_MEM, $TIR_AVG_MEM);
$query_all_archers_lm = "SELECT TPERSON, SUM(TSHOTS) AS TOTSHOTS_LM FROM tir_avg_mem WHERE YEAR(TDATE) = '" . $lmyear . "' AND MONTH(TDATE) = '" . $lastmonth . "' GROUP BY TPERSON ORDER BY TPERSON ASC";
$all_archers_lm = mysql_query($query_all_archers_lm, $TIR_AVG_MEM) or die(mysql_error());
$row_all_archers_lm = mysql_fetch_assoc($all_archers_lm);
$totalRows_all_archers_lm = mysql_num_rows($all_archers_lm);
?>
On the page :
<table width="170" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="85" align="center"><font size="1"><b><?php print $lang['Shots_archer']; ?></b></font></td>
<td width="85" align="center"><font size="1"><b><?php print $lang['Shots_archer_tot_lm']; ?></b></font></td>
</tr>
<?php do { ?>
<tr>
<td width="85" align="center"><font size="2"><?php echo $row_all_archers_lm['TPERSON']; ?></font></td>
<td width="85" align="center"><font size="2"><?php echo $row_all_archers_lm['TOTSHOTS_LM']; ?></font></td>
</tr>
<?php } while ($row_all_archers_lm = mysql_fetch_assoc($all_archers_lm)); ?>
</table>
And release the recordset :
<?php
mysql_free_result($all_archers_lm);
?>
Now this only gives me a resulting row when SUM(TSHOTS) returns a value, meaning a value for #shots has been entered for last month by that person. I want it to give me a row for every existing person, and in the case that this person has not entered any #shots last month, display 0 as the resulting value for SUM(TSHOTS).
Anyone ? Anyone ?
Tnx,
PF