Here is a snippet of code I am using on a page to put a team's results for a season into an array. I have to repeat this code 9 more times (19 more for basketball) on the page. The only difference in these examples are VW (to be replaced by others like SM, CE, etc.)
do {
if ($row_VW['Team1']=='VW') {
$Pts[1] = $Pts[1] + $row_VW['Pts_Team1'];
$OppPts[1] = $OppPts[1] + $row_VW['Pts_Team2'];
if (($row_VW['Pts_Team1'] - $row_VW['Pts_Team2']) > 0) {
$Won[1]++; }
elseif ($row_VW['Pts_Team1'] - $row_VW['Pts_Team2'] < 0) {
$Lost[1]++; } }
if ($row_VW['Team2']=='VW') {
$Pts[1] = $Pts[1] + $row_VW['Pts_Team2'];
$OppPts[1] = $OppPts[1] + $row_VW['Pts_Team1'];
if ($row_VW['Pts_Team2'] - $row_VW['Pts_Team1'] > 0) {
$Won[1]++; }
elseif ($row_VW['Pts_Team2'] - $row_VW['Pts_Team1'] < 0) {
$Lost[1]++; } }
} while ($row_VW = mysql_fetch_assoc($VW));
$row_VW refers to queried info. I have used Dreamweaver to help me create the queries. Here is the query it creates.
mysql_select_db($database_WBL_0506, $WBL_0506);
$query_VW = "SELECT * FROM wbl_football0506 WHERE Team1 = 'VW' OR Team2 = 'VW' ORDER BY Date ASC";
$VW = mysql_query($query_VW, $WBL_0506) or die(mysql_error());
$row_VW = mysql_fetch_assoc($VW);
$totalRows_VW = mysql_num_rows($VW);
I have tried to use functions before, but can never get them to work when a query is involved. It would really help to streamline my code to have a function that accepts parameter variable (VW, SM, CE, etc.)
i.e.
function results_array ($team_abb) {
all the crap above }
and call it with
results_array ($team_abb="VW"); // or whatever team I would need.
Is there a trick to this using a query in a function that is variable dependent? Is Dreamweaver screwing things up with the way it organizes the query? Am I just way off even trying this and should just suck it up and repeat this code?!?!?!