www.webdeveloper.com
Results 1 to 5 of 5

Thread: Vacation Planner

  1. #1
    Join Date
    May 2009
    Posts
    235

    Vacation Planner

    I have made a vacation planner to track employee vacations. But I want to add a feature to show conflicts. That is, only 1 person from each department can take vacation on a particular day. And I want a report for the month when vacations conflict. I cant seem to wrap my head around what to call, the day or the name. So I started with this

    PHP Code:
    <?php
    $sqla
    ="SELECT DISTINCT(name) AS name, day AS day FROM forms_calendar WHERE month='$month' AND year='$year' ";
    $resulta mysql_query($sqla) or die(("Error: ".mysql_error().$sqla));
    while (
    $rows=mysql_fetch_array($resulta)) {
    $day=$rows['day'];
    $name=$rows['name'];
    $date "$month-$day-$year";

    foreach (
    $department as $value) {

    //check for more than one name on that day in a particular department and show that name

    echo '<p>'.$name.' ~ '.$date.'</p>';
    }
    }
    ?>
    //check for more than one name on that day in a particular department and show that name
    this is the part i dont get - or it maybe that I have set the select wrong in the first place.

    Any help or ideas would be appreciated.

  2. #2
    Join Date
    May 2009
    Posts
    235
    This is what I have gotten so far but it only shows one of the names of that are in conflict not both.

    PHP Code:
    <?php
    $sqla
    ="SELECT DISTINCT(day) AS day, name AS name FROM forms_calendar WHERE month='$month' AND year='$year'";
    $resulta mysql_query($sqla) or die(("Error: ".mysql_error().$sqla));
    $z++;
    while (
    $rows=mysql_fetch_array($resulta)) {
    $day=$rows['day'];
    $name=$rows['name'];
    $date "$month-$day-$year";

    $depts = array('Facilities''Business Centre''Copy Centre''Reception''Hostess');
    $i=1;
    $depts[$i];
    foreach (
    $depts as $value) {
    if (
    $department==$value) { $z++; }
    }
    }
    if (
    $z >= 2) {
    echo 
    '<p>'.$name.' ~ '.$date.'</p>';
    }
    ?>

  3. #3
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    728
    Perhaps do this:

    - query for count of names grouped by month/day
    - review the results and look for counts > 1 - save those month/day values
    - do 2nd query for those month/day values getting names this time.

  4. #4
    Join Date
    May 2009
    Posts
    235
    ok help on 2 parts

    how do you group by 2 things I thought i could only group by one

    haw do you save the values

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    728
    A simple google on 'group by' would have provided you a quick answer.

    That said - in your query you just say "Group by month,day" or whatever your fields are named.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles