Using globals inside foreach loop to create automated statistics

having trouble getting the following code to output a particular stat… i have progressed to where i am no longer crashing the server with an endless loop, however still not getting desired output.
I am attempting to create an automatically updating Games Behind stat for my baseball gaming league. The code already outputs the league into a table that is split by division…
what i need to do is to be able to take the win/loss record of the division leader, and use it in a formula for the rest of the division…

[php] <?php

include(“inc/connection.php”);
$division =array(“Western Division”, “Mid-West Division”, “South-East Division”, “North-East Division”) ;
for($i=1;$i<5;$i++){
$stmt= $conn-> prepare(‘SELECT * FROM ddl WHERE division=? ORDER BY wins DESC, pct DESC’);
$stmt->execute(array($i));

$rs=$stmt-> fetchAll();
echo ‘

’. $division[($i-1)]. ‘’ ;

$v=1;
$taw=1;
$tal=1;
foreach($rs as $row) {

echo “

” . str_replace(’_’, ’ ‘, $row[‘team’]) . “”;
echo ‘’ . $row[‘wins’] . “”;
echo ‘’ . $row[‘loss’] . “”;
//this is where i am trying to create GB stat
if($GLOBALS[‘v’] =1){
$GLOBALS[‘taw’] =$row[‘wins’];
$GLOBAL[‘tal’] =$row[‘loss’];
echo ’ - ’ ;
} else{
echo ‘’. ((($taw-$row[‘wins’])+($row[‘loss’] - $tal))*0.5). ‘’;
}
//echo ‘.’.($row[“pct”]*1000).’’;
echo ‘’ . $row[‘rs’] . “”;
echo ‘’ . $row[‘ra’] . “”;
echo “”;
$GLOBALS[‘v’] ++;
}
}

?>[/php]

Here is current code… outputs GB as -

Any help greatly appreciated

N.B link to page http://mlbjunkies.com/DD/index.php

for those who see it $GLOBAL[‘tal’] has been changed to $GLOBALS… result still same… outputting only as if $v=1

Globals are ALWAYS a bad thing. So, why are you using them, as in what function are you trying to make them serve?

Sponsor our Newsletter | Privacy Policy | Terms of Service