Hello,
I'm working a script that iterates over several equations that require a mysql_query in order to complete. The script also has an exception to NOT insert values that divide by zero.
I would like to run one function for all players in my array, then run the second function for all players in my array, because otherwise the second function does not run for a player that 'broke the rules' for the first function.
The function I am referring to is storeValue. Therefore, I want to run storeValue for the first equation for all players, then move on to the next equation with the same function and do it again for all players.
Here is the code. Any help would be greatly appreciated.
I'm working a script that iterates over several equations that require a mysql_query in order to complete. The script also has an exception to NOT insert values that divide by zero.
I would like to run one function for all players in my array, then run the second function for all players in my array, because otherwise the second function does not run for a player that 'broke the rules' for the first function.
The function I am referring to is storeValue. Therefore, I want to run storeValue for the first equation for all players, then move on to the next equation with the same function and do it again for all players.
Code:
function storeValue ( $iPlayer, $iStat, $value ) {
$sql = sprintf( "INSERT INTO data SET player_id = '%d', statistic_id = '%d', value = '%s', day = NOW()", $iPlayer, $iStat, $value );
#mysql_query ( $sql );
echo "\n\t".$sql;
}
Code:
$aPlayer = getListOfPlayers();
foreach ( $aPlayer as $iPlayer => $name ) {
try {
$stat_id_2 = 4;
$stat_id_5 = 9;
$stat_id_6 = 10;
$a = getValue( $iPlayer, $stat_id_2 );
if ( $a === false )
throw new Exception( "Can't find stat #".$stat_id_2 );
$b = getValue( $iPlayer, $stat_id_5 );
if ( $b === false )
throw new Exception( "Can't find stat #".$stat_id_5 );
if ( $b == 0 )
throw new Exception( "Can't divide by zero <br/ >" );
$d = getValue( $iPlayer, $stat_id_6 );
if ( $b === false )
throw new Exception( "Can't find stat #".$stat_id_6 );
if ( $b == 0 )
throw new Exception( "Can't divide by zero <br/ >" );
$c = $a / $b;
storeValue( $iPlayer, $stat_id_new, $c );
echo "\n\t| Storing ".$c." for ".$name." - [#".$iPlayer."]<br/>";
$f = $a / $d;
storeValue( $iPlayer, $stat_id_new_2, $f );
echo "\n\t| Storing ".$f." for ".$name." - [#".$iPlayer."]<br/>";
} catch ( Exception $e ) {
echo "\nERROR - ".$name." - ".$e->getMessage();
}
}
Comment