Good day,
I have a for loop and whenever I try doing an update to my database, I always encounter an alert message depending on how many data I've edited.
How can I make the alert message appear only once?
Here is my code and I hope you can help me.
thanks a lot
Grace
<?/
function to edit shift of an employee
Comment by :GreggN
Date: November 24,2006
/
function ShiftEdit(){
$FromDate = $_POST['date_from'];
$r = strftime("%Y-%m-%d",$FromDate);
$ToDate = $_POST['date_to'];
$r = strftime("%Y-%m-%d",$ToDate);
echo "Start ".$ToDate."<br>";
echo "End ".$FromDate."<br>";
//get DIFFERENCE OF Start and End Date
$days = (strtotime($ToDate) - strtotime($FromDate)) / (60 * 60 * 24) ; //print $days;
echo "difference of days ".$days."<br>";
for($i=0;$i<=$days;$i++)
{
$today = $i * (60*60*24) + strtotime($FromDate);
$todayTime = strftime("%Y-%m-%d",$today);
$todayTimeFrom = date("Y-m-d",mktime(0,0,0,substr($todayTime,5,2),substr($todayTime,8,2),substr($todayTime,0,4)));
echo "todayTimeFrom: ".$todayTimeFrom."<br>";
$f = count($todayTimeFrom);
echo "grace".$f."grace";
$id = $_POST['txtempID'];
$shiftdesc2=$_POST['selShift'];
//check if date of shift exist from the database
$checkrecord = "select startDate from actatek_shiftmaster where userID = '$id' and startDate = '$todayTimeFrom'";
$checkquery = mysql_query($checkrecord);
$gregg2 = mysql_num_rows($checkquery);
$shift_row = mysql_fetch_array($checkquery);
$row1 = $shift_row['startDate'];
echo "z ".$row1."<br>";
if($gregg2==0)
{ ?>
<script>alert('No shift recorded in the range of date. Please check your filters.');
</script>
<?php
}
else
{
for ($a=0; $a<=$days; $a++)
{
echo "gregg2: ".$gregg2."<br>";
echo "range is ".$row1."<br>";
//update record
$UpdateShift = "UPDATE actatek_shiftmaster
SET shiftID ='$shiftdesc2',startdate='$todayTimeFrom' where startdate='$todayTimeFrom' and userID='$id'";
$UpdateResult = mysql_query($UpdateShift);
}
if(!$UpdateResult){
$Query ="Rollback";
mysq_query($Query);
}
else{
$UpdateShift ="COMMIT";
mysq_query($UpdateShift);
?>
<script>alert('grace');</script>
<?php
}
}
}
}
?>