Several questions here...I'm working on a form that takes user entered data, then pulls sports stats from the db to do the calculations. The user can specify how many points each hr, rbi, etc is worth. They can also specify which positions they want to calculate. On the results page, I'm using a switch statement to separate and show each positions results:
switch ($positionvalues) {
case 1:
whatever
break;
case : 2 etc
}
I've got it working for the most part, but my pagination and sort functions arent working. When clicked on it returns a blank page.
Do I have to have the page sort and query strings for the url in each Case? Or just once before the output of the page?
Please take a look here:
http://www.fantasybaseballresearch.com/baseball/customfbr.php
I have too much code to paste here...Would someone be willing to take a look if I sent it to them...
Here is one of the case below:
switch ($positionvalues) {
case 1:
/*
* Make a query string
*/
$query_string = "?year=$set_selected_year&position=$positionvalues&singlevalues=$singlevalues&dblvalue=$dblvalues&trpvalues=$
trpvalues&hrvalues=$hrvalues&rbivalues=$rbivalues&rvalues=$rvalues&sbvalues=$sbvalues&bbvalues=$bbvalues&
amp;kvalues=$kvalues";
// Grab the list of years, grouped by year
$sql = "SELECT DISTINCT year
FROM playerstats
GROUP BY year";
if (!$result = mysql_query($sql))
{
die("Could not execute query <strong>$query</strong> because " . mysql_error() . ".<br />") ;
}
$year_list = array();
while ($row = mysql_fetch_array($result))
{
$year_list[] = $row;
}
$hrvalues = $_REQUEST['hrvalues'];
$rbivalues = $_REQUEST['rbivalues'];
$rvalues = $_REQUEST['rvalues'];
$singlevalues= $_REQUEST['singlevalues'];
$sbvalues = $_REQUEST['sbvalues'];
$bbvalues = $_REQUEST['bbvalues'];
$kvalues = $_REQUEST['kvalues'];
$dblvalues = $_REQUEST['dblvalues'];
$trpvalues = $_REQUEST['trpvalues'];
// 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 = $positionvalues
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();
$i=0;
while ($row = mysql_fetch_array($result))
{
$stat_list[] = $row;
$stat_list[$i]['singles'] = (($row['hits']) - (($row['doubles']) + ($row['hr']) + ($row['triples'])));
$stat_list[$i]['customfbr_points'] = (($row['hr'] * $hrvalues) + ($row['rbi'] * $rbivalues) + ($row['runs'] * $rvalues) + ($row['sb'] * $sbvalues) + ($stat_list[$i]['singles'] * $singlevalues) + ($row['walks'] * $bbvalues) + ($row['so'] * $kvalues) + ($row['doubles'] * $dblvalues) + ($row['triples'] * $trpvalues));
$stat_list[$i]['iso'] = (($row['slg']) - ($row['avg']));
$i++;
}
// Now the queries are done
$total_items = count($stat_list); // example: 47
$per_page = $paging_lang['per_page'];
if (!isset($_GET['show_all']))
{
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
if ($start <> 0)
{
// Start was set and is now at least 10
$page_limit = ( ($total_items - $start) < $per_page) ? $total_items : ($start + $per_page);
}
else
{
$page_limit = $per_page;
}
}
else
{
$start = 0;
$page_limit = $total_items;
}
?>
<p align="left" class="small">* Click on arrows to sort stats.</p>
<?php
// This is where the sorting takes place
$sortstring = '';
$sortfields = array(
"lname",
"mlbteam_abbv",
"customfbr_points",
"ab",
"runs",
"hits",
"doubles",
"triples",
"hr",
"rbi",
"walks",
"so",
"sb",
"avg",
"slg",
"obp",
"ops",
"iso"
);
if (isset($_GET['sortby']))
{
$sortby = $_GET['sortby'];
if (isset($_GET['sortorder']) && ( $_GET['sortorder'] == 'a' || $_GET['sortorder'] == 'd' ))
{
$sortorder = ( $_GET['sortorder'] == 'a' ) ? SORT_ASC : SORT_DESC;
}
else
{
$sortorder = SORT_DESC;
}
if (!in_array($sortby, $sortfields))
{
$sortby = 'customfbr_points';
}
$stat_list = array_multi_sort($stat_list, $sortby, $sortorder);
$sortstring .= "&sortby=$sortby&sortorder=$sortorder";
}
else
{
if (count($stat_list) > 0)
{
$stat_list = array_multi_sort($stat_list, 'customfbr_points', SORT_DESC);
}
}
// paging output
echo print_paging($_SERVER['PHP_SELF'] . $query_string . $sortstring, $total_items, $per_page, $start);
?>
[B]
HTML TABLE/SORT HEADERS HERE (removed bc my code snippet was too long[/B]
<?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>
<?php
break;