I am new to programming so there may be a simple solution to my problem.
What I am trying to accomplish is finding duplicate fields entries in a MySQL column the entries are going to be dates example 01/20/13
I need to search through the date field and determine how many duplicate entries there are for a date then upon finding out the number I need to create a loop that will take the date change it into the name of the day the date is then add a . and a number after the .
So for example 01/20/13 is Sunday so in my database example below there are 4 duplicate entries so the output needs to be Sunday.1, Sunday.2, Sunday.3, Sunday.4
I have this functionality working in the PHP program below but I need it to search for duplicates in a 7 day range example 01/20/13 - 01/26/13, starting with Sunday and ending with Saturday. I don’t want to hard code a weeks worth of date values in. That is where my problem lies I don’t know where to go from here I am stuck. I can only think of hard coding the weeks worth of values in to get the desired results but I know there is an easier way.
My PHP code:
<?php
require '../TimeCard/DB.php';
$i = 1;
try{
$stmt = $conn->prepare('SELECT `date` FROM `timeRecords` WHERE `employeeID`= 1 ORDER BY date ');
$stmt->execute();
} catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
}
while($row = $stmt->fetch())
{
if ($row['date'] == "01/20/13"){
$date = date("l", strtotime($row['date']));
$$date = "Hello today is " . $date . "." . $i . "<br>";
echo $Sunday;
$i++;
}
}
?>
Database:
+----+------------+----------+--------+-------------------+-----------+------------+-----------+---------+
| id | employeeID | date | timeIn | jobDescription | equipType | unitNumber | unitHours | timeOut |
+----+------------+----------+--------+-------------------+-----------+------------+-----------+---------+
| 10 | 1 | 01/20/13 | 20:30 | Blah1 | | 01E | NULL | NULL |
| 2 | 1 | 01/20/13 | 1:00 | Test | | 02S | NULL | NULL |
| 9 | 1 | 01/20/13 | 13:00 | Blah12 | | 02E | NULL | NULL |
| 8 | 1 | 01/20/13 | 6:00 | Blah | | 02D | NULL | NULL |
| 1 | 1 | 01/21/13 | 09:12 | Worked in hubbard | Excavator | 01E | 8375 | 09:14 |
| 3 | 1 | 01/22/13 | | | | NULL | NULL | NULL |
| 4 | 1 | 01/23/13 | | | | NULL | NULL | NULL |
| 5 | 1 | 01/24/13 | | | | NULL | NULL | NULL |
| 6 | 1 | 01/25/13 | | | | NULL | NULL | NULL |
| 7 | 1 | 01/26/13 | | | | NULL | NULL | NULL |
+----+------------+----------+--------+-------------------+-----------+------------+-----------+---------+
Your approach seems to be too complicated. Find count for today’s date and given employee instead.