473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I loop over one function and then move onto another?

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.

Expand|Select|Wrap|Line Numbers
  1. function storeValue ( $iPlayer, $iStat, $value ) {
  2.     $sql = sprintf( "INSERT INTO data SET player_id = '%d', statistic_id = '%d', value = '%s', day = NOW()", $iPlayer,  $iStat,  $value );
  3.     #mysql_query ( $sql );
  4.     echo "\n\t".$sql;
  5.   }
  6.  
Here is the code. Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1.  $aPlayer = getListOfPlayers();
  2.   foreach ( $aPlayer as $iPlayer => $name ) {
  3.     try {
  4.  
  5.     $stat_id_2 = 4; 
  6.  $stat_id_5 = 9; 
  7.  $stat_id_6 = 10; 
  8.  
  9.  
  10.  $a = getValue( $iPlayer, $stat_id_2 ); 
  11.       if ( $a === false )
  12.         throw new Exception( "Can't find stat #".$stat_id_2 );
  13.  
  14.       $b = getValue( $iPlayer, $stat_id_5 ); 
  15.       if ( $b === false )
  16.         throw new Exception( "Can't find stat #".$stat_id_5 );
  17.       if ( $b == 0 )
  18.         throw new Exception( "Can't divide by zero <br/ >" );
  19.  
  20.        $d = getValue( $iPlayer, $stat_id_6 ); 
  21.       if ( $b === false )
  22.         throw new Exception( "Can't find stat #".$stat_id_6 );
  23.       if ( $b == 0 )
  24.         throw new Exception( "Can't divide by zero <br/ >" );
  25.  
  26.       $c = $a / $b; 
  27.       storeValue( $iPlayer, $stat_id_new, $c );
  28.       echo "\n\t| Storing ".$c." for ".$name." - [#".$iPlayer."]<br/>";
  29.  
  30.       $f = $a / $d; 
  31.       storeValue( $iPlayer, $stat_id_new_2, $f );
  32.       echo "\n\t| Storing ".$f." for ".$name." - [#".$iPlayer."]<br/>";
  33.  
  34.     } catch ( Exception $e ) {
  35.       echo "\nERROR - ".$name." - ".$e->getMessage();
  36.     }
  37.   }
  38.  
Sep 21 '10 #1
1 1093
I was able to resolve this. Thanks!
Sep 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: -DRB- | last post by:
Hi, I'm probably going to get harassed just for mentioning the unmentionable, but since I have if anyone could answer this question that would be much appreciated. As per the rather long...
1
by: iconsa | last post by:
Hello, Could i start work with personal edition then move all data to enterprise edition ? i've to design and code on workgroup environment then implement to windows server 2003. Do i just cut &...
6
by: Rey | last post by:
Howdy all. Am attempting to delete a large number of records (123K) from a table using: db.execute "delete from tblname" Then I double check (code below) to see if records still remain as...
3
by: MotorcycleIke | last post by:
I tried using WebRequest, but I am unable to simply redirect to an external aspx site and supply the userid and password and press their login button. Can anyone help? Thanks, I've spent a...
1
by: Max Bialystock | last post by:
Is it possible to take the first file in a folder (as sorted by name), email it to someone, then move the file to a separate directory? Any help at all will be much appreciated. Thanks, Max
3
by: Konstantin Andreev | last post by:
Hello, everybody. I've spent a lot of time reading "DB2 Information Center" and Raul Chong's book "Understanding DB2. Learning Visually with Examples", but still unable to answer this simple...
10
by: laredotornado | last post by:
Hi, Does anyone have a cross-browser function that given an id of a DIV element, can move the DIV to an absolute x,y position on the screen? Thanks, - Dave
0
NeoPa
by: NeoPa | last post by:
This code is quite old and may be bettered. If anyone feels they can produce better code for this function go ahead and PM me your effort. If I feel that it is better (More efficient & 100%...
0
by: Tetravaal | last post by:
I normally don't ask for help on forums, especially when I know that I am WAY out my league but if your feeling kind, feel free to contribute! I need to compare two cells (D2 and D3) and if they...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.