View Full Version : a problem regarding dateadd and whie loop

09-24-2005, 07:58 AM
hi all,
i m facing two problems. described here

1. i want to handle the date that will be in the range. i. e. i m asking from the user for the date range with two input boxes named as 'from' and 'to'. i want to insert the record for each date. so i want to add the date inside a loop and to increment i used ++ with the from date as

do some operation here like inserting date
then incrementing date with fromdate++;

the problem in this case is that if the range falls between feb25 to march3 then the date will keep on adding like after 28 feb it will become 29 30 31 32 33 and so on. is there any function to handle this date . tell me the solution top this problem plz.

2. the other problem is that i want to insert the record for date range as specified above and want to check that if the record for the date already exists if yes then the loop should be break and the msg displayed that date already exists u want to replace this record or not. if the answer is yes then the record is updated and the satrting value of the loop will be the next date of the repeating date. if no then the date will be continuing. here is the part of the code i have used plz refer it well. and give me the solution to this problem. i will be thankful to u.
echo "<html><head><title>Add Attedance Details</title>
<script language='javascript'>

function gotocheck()
a=confirm('Are u sure? u want to replace it');


echo "fdate".$fdate;
$repeatdt=$conn->execute("select attend_dt from attend where attend_dt='$fdate'");
$conn->debug=true; //conn is connection string
echo "repetead";
echo "<form action='$self_PHP' method='get' name='frmyesno'>
<input type='hidden' name='frmdt' value='$dt'>
<input type='hidden' name='todt' value='$tdate'>
<input type='hidden' name='add' value='$add'>
<table bgcolor='#cccccc' cellspacing='3' >
<tr><td colspan='2'>record for date $dt already exists Do u want to replace it</td></tr>
<tr><td>Yes &nbsp<input type='radio' value='yes' name='y_n' onclick='gotocheck()'></td>
<td>No &nbsp<input type='radio' value='no' name='y_n' onclick='gotocheck()'></td></tr>
<input type='submit'></td></form>";

echo "<br>";
echo $dt;
echo "i m in yes";
$conn->execute("update attend set empcode='$empid', hrs_worked=8, off_day='F',attend_dt='$fdate' ");
echo "updated records for empcode $empid date $fdate inserted";

echo " i m in else";

$conn->execute("insert into attend(empcode,attend_dt,hrs_worked,off_day) values('$empid','$fdate',8,'F')");
echo "records for empcode $empid date $fdate inserted";