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

  • SEARCH
  • Home
  • 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 9182817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:39:07+00:00 2026-06-17T18:39:07+00:00

I am having an issue trying to pinpoint a problem I am having, the

  • 0

I am having an issue trying to pinpoint a problem I am having, the code below loops twice and gives me an output of Match11Match111Match11Match111 I am really not sure where the problem is but it should only loop once.

<?php

function generateTimeCard($conn, $employeeID){

    // set current date
$date7 = date("m/d/y");

// parse about any English textual datetime description into a Unix timestamp
$ts = strtotime($date7);

// calculate the number of days since Monday
$dow = date('w', $ts);
$offset = $dow;
if ($offset < 0) {
    $offset = 6;
}

// calculate timestamp for the Monday
$ts = $ts - $offset*86400;

// loop from Monday till Sunday
for ($i = 0; $i < 7; $i++, $ts += 86400){

    $date1 = date("m/d/y", $ts);
    $date3 = date("l", $ts);
    $$date3 = $date1;
    $date2 = $date1;
    $day[$i] = $date1;

    $stmt = $conn->prepare('SELECT `employeeID`,`date`,`unitNumber`,`jobDescription`,`timeIn`,`timeOut`, `lunch`, TIMEDIFF(`timeOut`, `timeIn`)  
                            AS `totalTime` FROM `timeRecords` WHERE `date`= :day AND `employeeID`= :employeeID ORDER BY date,id;');

    $stmt->execute(array(':day'=>$day[$i], ':employeeID'=>$employeeID));    

    $dayOW = 1;

    while($row = $stmt->fetch()) {

           if ($row['lunch'] == "Yes"){
            echo "Match";
        } else{
            echo "1";
        }

        $dayCurrent = $date3 . "Hours." . $dayOW;
        $data[$dayCurrent] = $row['totalTime'];
        $timeDay = $date3 . "." . $dayOW;
        $unitNumber = $date3 . "UnitNumber." . $dayOW;
        $description = $date3 . "Description." . $dayOW;
        $data[$timeDay] = date("h:i A", strtotime($row['timeIn'])) . "/" . date("h:i A", strtotime($row['timeOut']));
        $data[$unitNumber] = $row['unitNumber'];
        $data[$description] = $row['jobDescription'];
        $dayOW++;
    }

    $stmt = $conn->prepare('SELECT `employeeID`, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(`timeOut`, `timeIn`)))) 
                            AS `totalDay` FROM `timeRecords` WHERE   `date` = :day
                            AND `employeeID` = :employeeID GROUP BY `employeeID`;');
    $stmt->execute(array(':day'=>$date1, ':employeeID'=>$employeeID));
    $row = $stmt->fetch();
    $totalDay = "Total" . $date3;

    $data[$totalDay] = $row['totalDay'];

}
$data['Week']= $Sunday . " - " . $Saturday;
return $data;

}

?>

My database looks like this

+----+------------+----------+--------+----------------------------+-------------+------------+-----------+---------+-------+
| id | employeeID | date     | timeIn | jobDescription             | equipType   | unitNumber | unitHours | timeOut | lunch |
+----+------------+----------+--------+----------------------------+-------------+------------+-----------+---------+-------+
|  1 |          1 | 01/20/13 | 6:00   | Worked in RockPort         | Excavator   | 01E        |      7238 | 17:13   | Yes   |
|  2 |          1 | 01/21/13 | 6:00   | Worked in Jefferson        | Excavator   | 01E        |      7238 | 17:17   |       |
|  3 |          1 | 01/22/13 | 6:00   | Worked in Jefferson        | Excavator   | 02E        |      7238 | 17:30   |       |
|  4 |          1 | 01/23/13 | 6:00   | Worked in Whispering Creek | Skid Loader | 32SL       |      2338 | 18:30   | Yes   |
|  5 |          1 | 01/24/13 | 8:00   | Worked in Hubbard          | Scraper     | 54C        |      9638 | 11:30   |       |
|  6 |          1 | 01/25/13 | 8:00   | Worked in Jefferson        | Dozer       | 4D         |       941 | 19:30   |       |
|  7 |          1 | 01/26/13 | 8:00   | Pushed Snow                | Loader      | 950H       |       342 | 20:30   |       |
+----+------------+----------+--------+----------------------------+-------------+------------+-----------+---------+-------+
  • 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-17T18:39:08+00:00Added an answer on June 17, 2026 at 6:39 pm

    By default, PDO fetches with index and column-name keys. So there are “duplicate” values. You want to change the fetch mode to FETCH_NUM (only index keys) ($stmt->fetch(PDO::FETCH_NUM)) so that values don’t appear under two mappings. http://php.net/manual/en/pdostatement.fetch.php

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

Sidebar

Related Questions

I'm having an issue trying to change the output of a message via my
I'm having an issue trying to NOT select a tablerow with the function: $(tr).click(function(e)
I am having an issue trying to make a small text-fantasy type game involving
I am having an issue trying to deal with timezones in the JQuery date/time
I am having an issue with trying to retrieve the contents of the view
I'm having an issue when trying to do something which should be as easy
I am having a big issue trying to delete from an UITableView. Just for
I'm having this issue when trying to use an ASPX page from a referenced
One of my users is having an issue when trying to open an Excel
Im having an issue when im trying to read in a text file while

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.