Hi all, and thanks for any help and/or suggestions you can offer.
I have been hacking this script for months now as a bit of an ongoing school project and to learn how it works. To date I had never tried to create more than one table from my results. I will admit to finding it difficult dealing with multiple tables.
The only thing I cant figure out is where to put $total +=$value;
It seems that regardess of where I put it I get a continual total of $value instead of the $total just being related to each table in question.
I have marked with /*=== where I thought something should go, but.....
Any help appreciated.
<?php
}
$build_table = "SELECT sports.sport AS sport, athlete.name AS name,portfolio.aid AS this_aid,portfolio.quantity AS quantity
FROM sports,athlete,portfolio
WHERE portfolio.aid=athlete.aid AND athlete.sid=sports.sportid AND portfolio.mid=$thismid ORDER BY this_aid";
$build_result = mysql_query($build_table) or die(mysql_error());
$hollow='Total';
$sport = '';
$name_title='Athlete';
$quantity_title='Quantity';
$avg_title='Points';
$value_title='Value';
$total=0;
$value=0;
for ($i = 1; $build_row=mysql_fetch_array($build_result); ++$i)
{
if($sport != $build_row['sport'])
{
if($i > 1)
{
echo "<tr>\n";
echo "<td colspan=3 align=right>". $hollow ."</td>\n";
echo "<td>" .$total. "</td>\n";
echo "</tr>\n\n";
echo "</table>\n\n";
}
echo "<p>";
echo "<table border=1 WIDTH=350>\n";
echo "<tr>\n";
echo "<td colspan=4 align=center bgcolor=#00FFFF>". $build_row['sport']."</td>";
echo "<tr>\n";
echo "<td>" . $name_title. "</td>\n";
echo "<td>" . $quantity_title . "</td>\n";
echo "<td>" . $avg_title . "</td>\n";
echo "<td>" . $value_title . "</td>\n";
echo "</tr>\n\n";
echo "</tr>\n\n";
}
echo "<tr>\n";
echo "<td>" . $build_row['name'] . "</td>\n";
$quantity=$build_row['quantity'];
echo "<td>" . $quantity . "</td>\n";
$this_aid=$build_row['this_aid'];
$base_points="SELECT MAX(points) AS base_points FROM base WHERE aid=$this_aid";
$base_result=mysql_query($base_points,$link);
if(!$base_result)
{
echo "you screwed up base_result";
}
else
{
WHILE($base_row = mysql_fetch_array($base_result))
{
$base_points=$base_row['base_points'];
$praise="SELECT MIN(points) AS praise_points FROM praise WHERE aid=$this_aid";
$praise_result=mysql_query($praise,$link);
if(!$praise_result)
{
echo "you screwed up praise_result";
}
else
{
WHILE($praise_row = mysql_fetch_array($praise_result))
{
$praise_points=$praise_row['praise_points'];
$sub=$praise_points-$base_points;
$half_sub=$sub/2;
$avg_points=$half_sub+$base_points;
$value=$avg_points$quantity;
/=============== I believe I need something here ($total +=$value😉 that doesnt work, gives running total for all tables ====================*/
}
echo "<td>" . $avg_points . "</td>\n";
echo "<td>" . $value . "</td>\n";
}
}
}
echo "</tr>\n\n";
$sport =$build_row['sport'];
}
echo "<tr>\n";
echo "<td colspan=3 align=right>". $hollow ."</td>\n";
echo "<td>" .$total. "</td>\n";
echo "</tr>\n\n";
echo "</table>\n\n";
}
?>