Reply
Troubles with a loop and array
Old 07-02-2004, 07:01 PM Troubles with a loop and array
halcyonandon's Avatar
Novice Talker

Posts: 12
hi...

I'm having an issue with a script i'm writing. I posted previously regarding it, but I got the script to run for one user (based on his ssn(social security #).

Now, I need to run the script with a loop so it goes through an array of all employee's social security numbers in the database.

Here is my script... something is off (seems to be a syntax error but im not sure what exactly, but i've noted each part and what its role should be...

PHP Code:
<?php

 
include (dirname(_FILE_) ."\..\..\..\LIU18Website/Portal/portalFunctions.php  ");

$pageDb'empTracking';
$accessLevel=getAccessLevel($pageDb);

if (
$accessLevel==0) {
  
$strPageTitle "Luzerne Intermediate Unit Portal- Employee Tracking";
  
writePortalHeader($strPageTitle);
  include (
dirname(_FILE_) ."\..\..\..\phpconnect.php  ");
}

?>



PHP Code:
<?

//update employee data







if(isset($_POST['update']))
{


    
//start loop for all users


$sql1"SELECT empSSN FROM empTracking.employee;";
$result1 mysql_query($sql1)or die("Loop could not be executed!");

                while(
$ssn mysql_fetch_array($result1))
                {


            
// get rid of everything allotted to this person for THIS year that isnt sick(17) or personal(13)
                 
$sql "DELETE FROM empTracking.allotment WHERE empSSN = '$ssn['empSSN']' AND absCode != '17' AND absCode != '13';";


             
//gets allottment for sick and personal (to be added up)
                 
$sql2 "SELECT allotment FROM empTracking.allotment
                 WHERE (absCode = '17' AND empSSN='$ssn['empSSN']') OR (absCode = '13' AND empSSN='$ssn['empSSN']');"
;

             
//selects carry over only for sick days(17)  [there might be an error if carry over is present for personal(13)]
                 
$sql3 "SELECT carryOver FROM empTracking.allotment WHERE empSSN = '$ssn['empSSN']' AND absCode = '17';";

            
//gets all the days use for sick and personal (to be added up)
                 
$sql4 "SELECT daysUsed FROM empTracking.absence WHERE (empSSN = '$ssn['empSSN']') AND (absCode = '17' OR absCode = '13');";


    
// run SQL against the DB

                
$result mysql_query($sql)
                or die (
"Couldn't execute query1.");  //no need to catch result

                
$result2 mysql_query($sql2)
                or die (
"Couldn't execute query2.");  // $total=$total+$row[x]
                
$everythingForThisYear 0;
                while(
$myrow mysql_fetch_array($result2))
                {
                    
$everythingForThisYear $everythingForThisYear $myrow['allotment'];
                }


                
$result3 mysql_query($sql3)
                or die (
"Couldn't execute query3.");  //should be one number, so no WHILE LOOP
                
$myrow mysql_fetch_array($result3);
                
$old_carry_over $myrow['carryOver'];


                
$result4 mysql_query($sql4)
                or die (
"Couldn't execute query4.");  // $total=$total+$row[x]
                
$absenceTotal 0;
                while(
$myrow mysql_fetch_array($result4))
                {
                    
$absenceTotal $absenceTotal $myrow['daysUsed'];
                }


$available $old_Carry_Over $everythingForThisYear;
$new_Carry_Over $available $absenceTotal;


// do new carry over calculation here




//after all calculations, set the new carry over
                 
$sql5 "UPDATE empTracking.allotment SET carryOver='$new_Carry_Over' WHERE empSSN='$ssn['empSSN']' AND absCode='17';";

                
$result5 mysql_query($sql5)
                or die (
"Couldn't execute query5.");  //no need to catch result




        
mysql_free_result($result);
        
mysql_free_result($result2);
        
mysql_free_result($result3);
        
mysql_free_result($result4);
        
mysql_free_result($result5);

}
//end loop for all users


}//end of if POST UPDATE


    
?>

I use a html form submit button to launch the script...
So, my question is... what is wrong with my script that the loop/array for ssn implemented wont run.

Also... does anyone know a good debugger/error check for php?

Last edited by halcyonandon : 07-03-2004 at 05:24 PM.
halcyonandon is offline
Reply With Quote
View Public Profile Visit halcyonandon's homepage!
 
When You Register, These Ads Go Away!
     
Old 07-03-2004, 11:58 AM bonk
halcyonandon's Avatar
Novice Talker

Posts: 12
/bonk
halcyonandon is offline
Reply With Quote
View Public Profile Visit halcyonandon's homepage!
 
Old 07-03-2004, 12:23 PM
cmonkey's Avatar
Ultra Talker

Posts: 268
could you edit your post and put all that code in php tags, it would make it a little easier to digest.
cmonkey is offline
Reply With Quote
View Public Profile
 
Old 07-03-2004, 05:27 PM
halcyonandon's Avatar
Novice Talker

Posts: 12
ok... its in php tags now... sorry about that
halcyonandon is offline
Reply With Quote
View Public Profile Visit halcyonandon's homepage!
 
Old 07-03-2004, 05:39 PM
dbzguy's Avatar
Ultra Talker

Posts: 345
Location: Artic
it might help me if you put in the includes also
__________________
W3 Dynamic Webhosting-Great Hosting, great service, GREAT PRICES!

PHP Code:
<?PHP if(ping == true) { attackuserip(); } ?>
dbzguy is offline
Reply With Quote
View Public Profile Visit dbzguy's homepage!
 
Old 07-04-2004, 01:18 AM
halcyonandon's Avatar
Novice Talker

Posts: 12
not really... the script worked for one social security number... but then I added the array for every social in the database. I need it to loop through for each ssn in the db... so i was thinkin FOREACH might be a better alternative to what I tried...

But... portalfuntions has the universal variables to the portal i wrote, which doesnt conflict with anything in this script and the other is the db connect script...
halcyonandon is offline
Reply With Quote
View Public Profile Visit halcyonandon's homepage!
 
Reply     « Reply to Troubles with a loop and array
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15061 seconds with 13 queries