I'm trying to make a form that will collect user entered values. These values will be used to calculate points based on sports stats pulled from my db.
This is the form that I have so far:
<div class="stathead">Calculate Custom FBR Points</div>
<?php
// look for no POST entries, or the RESET button
if (count($_POST) == 0 or @$_POST['reset']) {
// POST array is empty - set initial values
$hrvalues = 4;
$hitsvalues = 1;
$rbivalues = 1;
$rvalues = 1;
$sbvalues = 2;
} else {
// retrieve values from POST array
$hrvalues = $_POST['hrvalues'];
$hitsvalues = $_POST['hitsvalues'];
$rbivalues = $_POST['rbivalues'];
$rvalues = $_POST['rvalues'];
$sbvalues = $_POST['sbvalues'];
} // if
// validate all fields
$error = array();
if (!empty($hrvalues)) {
if (!ereg('^[[:digit:]]+$', $hrvalues)) {
$error['hrvalues'] = "must be an integer";
} else {
$hrvalues = (int)$hrvalues; // convert to integer
} // if
} // if
if (!empty($hitsvalues)) {
if (!ereg('^[[:digit:]]+$', $hitsvalues)) {
$error['hitsvalues'] = "must be an integer";
} else {
$hitsvalues = (int)$hitsvalues; // convert to integer
} // if
} // if
if (!empty($rbivalues)) {
if (!ereg('^[[:digit:]]+$', $rbivalues)) {
$error['rbivalues'] = "must be an integer";
} else {
$rbivalues = (int)$rbivalues; // convert to integer
} // if
} // if
if (!empty($rvalues)) {
if (!ereg('^[[:digit:]]+$', $rvalues)) {
$error['rvalues'] = "must be an integer";
} else {
$rvalues = (int)$rvalues; // convert to integer
} // if
} // if
if (!empty($sbvalues)) {
if (!ereg('^[[:digit:]]+$', $sbvalues)) {
$error['sbvalues'] = "must be an integer";
} else {
$sbvalues = (int)$sbsvalues; // convert to integer
} // if
} // if
if (count($error) == 0) {
// no errors - perform requested action
if (isset($_POST['button99'])) {
$customfbr_points = calc_customfbr_points($hrvalues, $hitsvalues, $rbivalues, $rvalues, $sbvalues);
} // if
} // if
?>
<form action="testit2.php" method="POST">
<table border="1">
<colgroup align="right">
<colgroup align="left">
<colgroup align="center">
<tr>
<td>Points/Hit</td><td><input type="text" name="hitsvalues" value="<?= $hitsvalues ?>" />
</tr>
<tr>
<td>Points/HR</td><td><input type="text" name="hrvalues" value="<?= $hrvalues ?>" />
</td>
</tr>
<tr>
<td>Points/RBI</td><td><input type="text" name="rbivalues" value="<?= $rbivalues ?>" />
</td>
</tr>
<tr>
<td>Points/R</td><td><input type="text" name="rvalues" value="<?= $rvalues ?>" />
</td>
</tr>
<tr>
<td>Points/SB</td><td><input type="text" name="sbvalues" value="<?= $sbvalues ?>" />
</td>
<td><input type="submit" name="button99" value="Calculate FBR Values" /></td>
</tr>
</table>
</form>
</div>
The user entered values should be passed to the actual stat page for calculations. This is what I have so far....I know its way off, but hopefully its a start (only partial code below):
In the first query below, you will see where I want to use the user values for calculations. So far, all my calculations are going to 0.
// This query gets the data the user has requested
$sql = "SELECT ps.*, p.*, t.*
FROM playerstats ps
INNER JOIN
(
players p INNER JOIN mlbteams t
ON t.mlbteam_id = p.mlbteam_id
)
ON ps.player_id = p.player_id
WHERE p.position_id = $set_selected_position
AND ps.year = $set_selected_year
ORDER BY hr DESC";
if (!$result = mysql_query($sql))
{
die("Could not get the statistics you requested: " . mysql_error() . ".<br />");
}
$stat_list = array();
while ($row = mysql_fetch_array($result))
{
$customfbr_points = (($row['hr'] * '$hrvalues') + ($row['rbi'] * '$rbivalues') + ($row['runs'] * '$rvalues') + ($row['sb'] * '$sbvalues') + ($row['hits'] * '$hitsvalues'));
$stat_list[] = $row;
}
// Now the queries are done
?>
<?php
for ($i = $start; $i < $page_limit; $i++)
{
// Row color selector
$row_color = ( !($i % 2) ) ? ' bgcolor=#ffffff' : '';
$lname = $stat_list[$i]['lname'];
$fname = $stat_list[$i]['fname'];
$ab = $stat_list[$i]['ab'];
$runs = $stat_list[$i]['runs'];
$hits = $stat_list[$i]['hits'];
$doubles = $stat_list[$i]['doubles'];
$triples = $stat_list[$i]['triples'];
$player_id = $stat_list[$i]['player_id'];
$mlbteamabbv = $stat_list[$i]['mlbteam_abbv'];
$hr = $stat_list[$i]['hr'];
$rbi = $stat_list[$i]['rbi'];
$walks = $stat_list[$i]['walks'];
$so = $stat_list[$i]['so'];
$sb = $stat_list[$i]['sb'];
$avg = $stat_list[$i]['avg'];
$slg = $stat_list[$i]['slg'];
$obp = $stat_list[$i]['obp'];
$ops = $stat_list[$i]['ops'];
$points = $stat_list[$i]['customfbr_points'];
$pointsround = ROUND($points, 1);
$iso = $stat_list[$i]['iso'];
$isoround = ROUND($iso, 3);
echo "\t<tr>\n";
echo "\t\t<td$row_color><a href='/baseball/players.php?player_id=$player_id'>$fname $lname</td>\n";
echo "\t\t<td$row_color>$mlbteamabbv</td>\n";
echo "\t\t<td$row_color$row_color align=\"center\">$pointsround</td>\n";
echo "\t\t<td$row_color align=\"center\">$ab</td>\n";
echo "\t\t<td$row_color align=\"center\">$runs</td>\n";
echo "\t\t<td$row_color align=\"center\">$hits</td>\n";
echo "\t\t<td$row_color align=\"center\">$doubles</td>\n";
echo "\t\t<td$row_color align=\"center\">$triples</td>\n";
echo "\t\t<td$row_color align=\"center\">$hr</td>\n";
echo "\t\t<td$row_color align=\"center\">$rbi</td>\n";
echo "\t\t<td$row_color align=\"center\">$walks</td>\n";
echo "\t\t<td$row_color align=\"center\">$so</td>\n";
echo "\t\t<td$row_color align=\"center\">$sb</td>\n";
echo "\t\t<td$row_color align=\"center\">$avg</td>\n";
echo "\t\t<td$row_color align=\"center\">$slg</td>\n";
echo "\t\t<td$row_color align=\"center\">$obp</td>\n";
echo "\t\t<td$row_color align=\"center\">$ops</td>\n";
echo "\t\t<td$row_color align=\"center\">$isoround</td>\n";
echo "\t</tr>\n";
}
?>
</table>
I've removed the sort and paging functions since it isnt really needed for this problem. Any suggestions would be appreciated