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.
|