Jump to content

gearsgod

Members
  • Posts

    16
  • Joined

  • Last visited

About gearsgod

  • Birthday 01/04/1990

Profile Information

  • Gender
    Male
  • Location
    Washington

Contact Methods

  • Yahoo
    name_hidden_forever

gearsgod's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I just cant in over a week figure out how I would go about setting up this work time sheet, that displays my employees work times and find any conflicting work hours. But man I have been stumped on getting this code to work! Could anyone fix, or even better teach me a much better way to acomplish this? function time_sheet_day($DB){ $manager_id = $_SESSION['man_id']; $today = date('l'); $year = date('Y'); $ddate = @date(); $date = new DateTime($ddate); $week = $date->format("W"); $page = "<table><tbody><tr><th>ID</th><th>Crew</th><th>Position</th><th>Start Time</th><th>End Time</th></tr>"; $time_sheet_db = $DB->query("SELECT {$today},member_id FROM calendar WHERE manager_id = {$manager_id} AND Week = {$week} AND Year = {$year}"); $time_sheet = []; while($time = $time_sheet_db->fetcharray(SQLITE3_ASSOC)){ $hours = explode('-', $time[$today]); $time_sheet[] = array($time['member_id'], $hours[0], $hours[1]); } $member_info = []; $time_check = $time_sheet; $conflicts = []; $rater = 0; foreach($time_check as $checker){ if($checker[0] == $time_check[$rater][0]){ $rater = $rater + 1; continue; } if($checker[1] == $time_check[$rater][1]){ $conflicts[] = array($checker[0], $time_check[$rater][0], $checker[1]); } $rater = $rater + 1; } foreach($time_sheet as $member){ $member_info_db = $DB->query("SELECT username,crew,postion FROM Members WHERE ID = {$member[0]}"); $member_info = $member_info_db->fetcharray(SQLITE3_ASSOC); $found_conflict=array_find($conflicts, $member[0]); print_r($found_conflict); if($found_conflict == False){ $page .= "<tr><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } else { $page .= "<tr style='background-color:#FF0000'><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } } $page .= '</tbody></table>'; echo ($page); } function array_find($parents, $searched) { if (empty($searched) || empty($parents)) { return false; } foreach ($parents as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; }
  2. The errors are gone, but now it does not find conflicts in an array and point out the key for it :/ example: Array ( [0] => Array ( [0] => 12 [1] => 12 [2] => 1pm ) [1] => Array ( [0] => 13 [1] => 13 [2] => 1pm ) ) as you can see, they both are set at 1pm, it needs to return a true, but my script thinks its still false
  3. I keep getting these errors, running php 5.4; Notice: Undefined variable: value in C:\xampp\htdocs\BK\functions.php on line 133 Warning: Creating default object from empty value in C:\xampp\htdocs\BK\functions.php on line 133 Fatal error: Cannot access empty property in C:\xampp\htdocs\BK\functions.php on line 133 and heres my code; 128 function array_find($parents, $searched) { 129 if (empty($searched) || empty($parents)) { 130 return false; 131 } 132 133 foreach ($parents as $key -> $value) { 134 $exists = true; 135 foreach ($searched as $skey -> $svalue) { 136 $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); 137 } 138 if($exists){ return $key; } 139 } 140 141 return false; 142 }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.