Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:34:27+00:00 2026-06-06T11:34:27+00:00

This is my new code, its almost working, but I think my while loop

  • 0

This is my new code, its almost working, but I think my while loop is wrong some where?

Same as before, gets users taken sick puts it into a var. Then get users entitlement based on years of service, then work out what they have taken and see if the user has used all the full entitlement, then to see if they have used all there half pay entitlement.

Please Help?

if($this->CURRENT_USER['User']['role_id'] > 3) { //locks out user types

        //Get Holidaytypes
        $types = $this->Holiday->find(
            'all',
            array(
             'conditions' => array(
                                 'Holiday.holidaystype_id' => 3,
                                 'Holiday.user_id' => $id
             )));

        //Get starting date
        $contracts = $this->Holiday->User->Contract->find(
            'all',
            array(
                'conditions' => array(
                'Contract.user_id' => $id//$data['user_id']),
                'order' => array('Contract.startson' => 'ASC')
            )
        );
    //Get How Many sick days
    foreach ($types as $key => $value) {
            global $SickTotal; 
            $typesDataEnds =  strftime ("%u-%d-%Y", $types[$key]['Holiday']['endson']);
            $typesDataStarts = strftime ("%u-%d-%Y", $types[$key]['Holiday']['startson']);

            $SickTotal = count($typesDataEnds - $typesDataStarts);  
            //echo $SickTotal;

        //Get Contract Start & End Dates
        $start = array_shift($contracts);
        $end = array_pop($contracts);

        $endDate = $end['Contract']['endson'];
        $startDate = $start['Contract']['startson'];

        if (empty($endDate)) {
                $endDate = time('now');
        }
        if (!empty($startDate)) {
            $SortEnd = strftime("%Y", $endDate);
            $SortStart = strftime("%Y", $startDate);
            $YearsService = $SortEnd - $SortStart;

            if ($YearsService <= 1) {
                    $SetFullEntitlement = 5;
                    $SetHalfEntitlement = 5;
                    //echo 'one year';
            } elseif ($YearsService >= 2) {
                    $SetFullEntitlement = 10;
                    $SetHalfEntitlement = 10;
                    //echo 'two years';
            } elseif ($YearsService >= 5) {
                    $SetFullEntitlement = 20;
                    $SetHalfEntitlement = 20;
                    //echo 'up to five years';
            } elseif ($YearsService > 5) {
                    $SetFullEntitlement = 30;
                    $SetHalfEntitlement = 30;
                    //echo 'five years or more';
            } else {
                    $SetFullEntitlement = 0;
                    $SetHalfEntitlement = 0;
                    //echo 'no sick pay';
            }
        } else {
            $YearsService = 0;
            //echo 'Sorry No Start Date For You Found!';
        }

        while ($SickTotal > 0) {
            if ($SetFullEntitlement != 0) {
                $SetFullEntitlement--;
            } elseif ($SetHalfEntitlement != 0) {
                $SetHalfEntitlement--;
            }
        }

        echo 'FullPay:';
        echo $SetFullEntitlement;
        echo '<br/><br/>Halpay:';
        echo $SetHalfEntitlement;
        echo $SickTotal;
    } 

        debug($types);
        die();  
        //$this->render('/artists/holidayslist');

    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:34:29+00:00Added an answer on June 6, 2026 at 11:34 am

    I’m not quite sure I follow exactly what you are trying to do here but you could tidy up your code a bit and save on lines of code. I assume that $startdate is how many years ago the user started.

    $sickdays= array( 0=>5, 1=>10, 2=>20, 5=>30 );
    $userdays= 0;
    foreach ( array_keys( $sickdays ) as $years_service )
    {
       if ( $years_service <= $startdate )
          $userdays=$sickdays[$years_service];
    }
    

    Now $userdays should be the correct number of paid sick days and half days ( the two are always the same in your example ) for this user. A simple comparison should be sufficient to check whether they have taken less or more than their allotted number of days and half days.

    I haven’t tried this as I’m not working with PHP today, so I’m sure someone will shoot me down directly, but by setting your variables once and writing fewer lines you should find your code gets easier to maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the new code with the update from capdragon, but now it would
I'm new to this kabeja package so please can some one provide code example
While it seems that this has been asked many times before, but there's a
Consider this code: new Ajax.Request('?service=example', { parameters : {tags : 'exceptions'}, onSuccess : this.dataReceived.bind(this)
I have a lot of C# VS2008 code that looks like this: new SqlParameter(@Description,
I have this problem: I want to generate a new source code file from
Hi I have below pseudo code with throws an exception like this throw new
I have the following code: private void _DoValidate(object sender, DoWorkEventArgs e) { this.BeginInvoke(new MethodInvoker(()
Actually my code is: LinearLayout ll = new LinearLayout(this); ll.setId(i); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); ll.setPadding(0, 0,
The following code don't work- TextView myLocation = new TextView(this); myLocation.setText(Sodala, Jaipur, Rajasthan, IN);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.