Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a problem regarding dateadd and whie loop

    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

    while(fromdate<=todate)
    {
    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');
    if(a==true)
    {
    alert(true);
    document.frmyesno.flag.value=1;
    fl=document.frmyesno.flag.value;
    alert(fl);

    }
    else
    {
    document.frmyesno.flag.value=0;
    document.frmdt.value=document.frmdt.value+1;
    document.frmyesno.submit();
    }
    }
    </script></head>";

    while($fdate<=$tdate)
    {
    echo "fdate".$fdate;
    $repeatdt=$conn->execute("select attend_dt from attend where attend_dt='$fdate'");
    $conn->debug=true; //conn is connection string
    if(!$repeatdt->EOF)
    {
    $dt=$fdate;
    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>";

    if($flag==1)
    {
    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";

    }
    $fdate++;
    break;
    }
    else
    {
    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";
    $fdate++;

    }
    }
    Last edited by mongaraman; 09-24-2005 at 08:18 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •