I am trying to sum the results of an array. The sum is correct, but it only lists the last record and then the sum of all of the other records that should be displayed, but they are not. Here is the code I am using:
function display_search_results($query)
{
$result = userdbExec($query);
if(!odbc_fetch_into($result, $row))
echo "No match found!<HR>";
else
{
?>
<TABLE cellspacing="5" cellpadding="5"><tr><td><b><u>ID</u></b></TD><td><b><u>Distributor Name</u></b></TD><td><b><u>Title</u></b></TD><td><b><u>Phone</u></b></TD><td><b><u>Start Date</u></b></TD><td><b><u>Period Sales</u></b></TD></TR>
<?
do{
print("<tr><td>" . $row[0] . "</td>");
print("<td>" . $row[1] . " " . $row[2] . "</td>");
print("<td>" . $row[3] . "</td>");
print("<td>" . $row[4] . "</td>");
print("<td>" . $row[5] . "</td>");
print("<td>$".number_format($row[6],2)."</td></tr>");
}
while(odbc_fetch_into($result, $row));
print("<tr><td><td><td><td><td><b>Total </b><td>$".number_format($row[7],2)." </td></td></td></td></td></td></tr>");
print("</table><HR>");
}
}
do_unlinked_html_header("Downline Genealogy Report");
/* Search */
echo "Genealogy Downline Report Search for Distributor ID <b>" . $valid_user . "</b><BR>";
$query = "SELECT dm_id, dm_first_name, dm_last_name, di_pay_title, dm_phone, di_start_date, di_period_sales, SUM(di_period_sales) FROM distributor_main, distributor_sales
WHERE distributor_sales.di_id = distributor_main.dm_id AND dm_sponsor_id ='$valid_user'";
display_search_results($query);
do_html_URL("member.php", "Return to the Main Menu");
do_html_footer();
userdbClose();
?>
If anyone could help me out, i'd appreciate it.