Jump to content

mstoehr

New Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About mstoehr

  • Rank
    Newbie
  1. $row_admin['total_staff'] = 5; //set in loop above $current_pick_staff = 1; //changes on page load AAAAWWWW: $sql = "SELECT * FROM vac_pick_order WHERE pick_order ='$current_pick_staff'"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)){ if($row77['vac_c_counter'] > 0){ //<---- this is where the GOTO is needed if this goto the next staff member $current_pick_emp_num = $row77['emp_num']; }ELSE{ if ($current_pick_staff == $row_admin['total_staff']){ $current_pick_staff = 1; }ELSE{ $current_pick_staff++; } $sqla = "UPDATE vac_admin SET current_pick_staff='$current_pick_staff'"; if (mysqli_query($conn, $sqla)) { //echo "Record updated successfully a"; } else { echo "Error updating record: a " . mysqli_error($conn); } GOTO AAAAWWWW; } I think the GOTO is causing problems with my web host.It works fine on a local xampp server but not after uploading to Godaddy. It seems to freeze the server. How can i loop back to the beginning changing "$current_pick_staff" up by one without GOTO. $current_pick_staff loops around 1->5 then back to 1 (1 2 3 4 5 1 2 3 4 5 and so on)
  2. Thank you for your input. Got it working now!!
  3. That's a great bit of code Thanks. But i still have a problem. As the loop continues staff run out of vacation weeks therefore they need to be skipped and the next person can pick in the round. How do i skip a staff member that has run out of days to pick? The vac_pick_order -> vac_c_counter starts at the amount of vacation the staff is given and every week they pick is deducted from that count. When its 0 they should be skipped and the next person can pick. $qq = ($row_admin['current_pick_staff'] + $row_admin['current_round_number'] - 2) % ($row_admin['total_staff']) + 1; $sql = "SELECT * FROM vac_pick_order WHERE pick_year='$year' vac_c_counter>0 && pick_order='$qq'"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)){ if($row['vac_c_counter'] > 0){ $current_pick_emp_num = $row['emp_num']; }ELSE{ GOTO NEXT STAFF?????? } }
  4. This is my DB structure ~~~~~Table ~~~~vac_admin Id | pick_year | current_pick_staff ------------------------------------------------------------- 1 | 2020 | 1 ~~~~~Table ~~~~vac_pick_order Id | pick_year | pick_order | vac_c_counter | emp_number ------------------------------------------------------------------------------------------------------------- 1 | 2020 | 1 | 3 | 11111111 2 | 2020 | 2 | 5 | 22222222 3 | 2020 | 3 | 3 | 33333333 ~~~~~Table ~~~~vac_picks~~~the final result of picks Id | pick_year | date | emp_number ----------------------------------------------------------------------------- 1 | 2020 | 2020-05-15 | 11111111 2 | 2020 | 2020-02-20 | 22222222 3 | 2020 | 2020-12-25 | 33333333
  5. Man i just can't wrap my head around this bit of code 😫😫 I have been trying all day still not the result i need.
  6. SORRY I made a BIG ERROR explaining what i need . In every round the order changes by 1 every time ~~~~~~First round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 3 weeks available STAFF 2 - PICK ORDER 2 - 5 weeks available STAFF 3 - PICK ORDER 3 - 3 weeks available Staff 1 takes 2 Weeks Staff 2 takes 1 Weeks Staff 3 takes 3 Weeks ~~~~~~Second round of picking~~~~~~ STAFF 2 - PICK ORDER 1 - 4 weeks available STAFF 3 - PICK ORDER 2 - No weeks left STAFF 1 - PICK ORDER 3 - 1 weeks available Staff 2 takes 3 Weeks Staff 3 Skipped Staff 1 takes 1 Weeks ~~~~~~Third round of picking~~~~~~ STAFF 3 - PICK ORDER 1 - No weeks left STAFF 1 - PICK ORDER 2 - No weeks left STAFF 2 - PICK ORDER 3 - 1 weeks available Staff 3 Skipped Staff 1 Skipped Staff 1 takes 1 Weeks ~~~~~~~~~~~~ All staff 0 weeks left end thanks in advance for any help
  7. I have 3 staff members that need to pick vacation in a certain order. Each have X weeks vacation and can pick off a calendar their choice 1-3 weeks per round. I'm trying to loop through the DB to find who is next to pick with weeks left ~~~~~~First round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 3 weeks available STAFF 2 - PICK ORDER 2 - 5 weeks available STAFF 3 - PICK ORDER 3 - 3 weeks available Staff 1 takes 2 Weeks Staff 2 takes 1 Weeks Staff 3 takes 3 Weeks ~~~~~~Second round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 1 weeks available STAFF 2 - PICK ORDER 2 - 4 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 takes 1 Weeks Staff 2 takes 3 Weeks Staff 3 Skipped ~~~~~~Third round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - No weeks left STAFF 2 - PICK ORDER 2 - 1 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 Skipped Staff 2 takes 1 Weeks Staff 3 Skipped ~~~~~~~~~~~~ All staff 0 weeks left end --calendar.php-- $year=2020; $sql = "SELECT * FROM vac_admin WHERE pick_year='$year'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row_admin = mysqli_fetch_assoc($result); } $current_pick_staff = $row_admin['current_pick_staff']; $sql = "SELECT * FROM vac_pick_order WHERE pick_year='$year' && pick_order = '$current_pick_staff'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if($row['vac_c_counter'] < 0){ $emp_num = $row['emp_num']; }ELSE{ ?????????????????? goto next staff with weeks > 0 ?????Somthing like if ($current_pick_staff == 3){ $current_pick_staff = 1; }ELSE{ $current_pick_staff++; } ?????????????????? } ~<FORM>~~~~~~~~~~~~~~~~~~~~~ Staff with $emp_num can now pick ~~~~~~ $_POST -> $date = XXXX-XX-XX; $num_weeks = X; $emp_num; ~</FORM>~~~~~~~~~~~~~~~~~~~~~ --process.php-- $year = 2020; $date = $_POST['date']; $num_weeks = $_POST['num_weeks']; $emp_num = $_POST['emp_num']; $sql = "INSERT INTO vac_picks (pick_year,emp_num,date) VALUES ($year,$emp_num,$date)"; $sql = "UPDATE vac_pick_order SET vac_c_counter=vac_c_counter - $num_weeks WHERE emp_num='$emp_num'; $sql = "UPDATE vac_admin SET pick_order=pick_order +1 WHERE pick_year='$year' ; Then back to calendar.php until all weeks gone.
  8. WOW so simple Thank you works great
  9. I'm trying to get dates out of the DB for an overtime system. The dates are for staff with the oldest seniority first to the newest staff last. But when 2 or more people start on the same date. I need to randomly order them every time i make a query to the DB In my database, there is a column called start_date. I need to select all the dates in order of oldest date to newest date. $sql = "SELECT * FROM staff ORDER BY start_date DESC"; That's easy BUT... If there are 2 or more of the same start dates selected those dates in random order OUTPUT Example: 1988-01-01 <-- oldest date 1988-02-02 1990-01-01 1990-05-05 2000-01-01 <-- these 3 in random order 2000-01-01 <-- these 3 in random order 2000-01-01 <-- these 3 in random order 2000-02-05 2005-12-12 2006-02-02 <-- these 5 in random order 2006-02-02 <-- these 5 in random order 2006-02-02 <-- these 5 in random order 2006-02-02 <-- these 5 in random order 2006-02-02 <-- these 5 in random order 2010-05-09 2019-01-14 <-- newest date etc
×
×
  • 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.