www.webdeveloper.com
Results 1 to 3 of 3

Thread: Building a PC User allocation system

  1. #1
    Join Date
    Jun 2010
    Posts
    32

    Question Building a PC User allocation system

    Hi all.

    I'm looking to build a website in PHP for the training team in my work place. They have an allocation of PC Users to use whilst in the training environment.

    For arguments sake lets say:
    Site1Usr1 to Site1Usr80
    Site2Usr1 to Site2Usr80
    Site3Usr1 to Site3Usr80

    A list of trainers will have access to the site. Trainer A will log on and say I need 24 users, at site 1. The website will allocate the first 24 available users on site 1.

    The site will remember that Trainer 1 has these 24 users. If the trainer has any difficult in using any of the PC Users, they can mark the PC user as faulty. The site will pull the PC user from this Trainer, find the next available free PC User and add this to the users assigned to them.

    The bit I can see being the biggest challenge is - A Trainer needs 30 users. Users 1 to 40 are free, but user 22, 26 and 28 are out of use because we're waiting for IT to fix these accounts. How would I build it to allocate user 1-21,23 - 25,27, 29-33?

    Or am I trying to build something here that's already out there as a polished and working product?

    Your advice, guidance and knowledge is welcomed.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    If this is database-driven (which it sounds like it should be), then it should be fairly simple to control via the DB design and the SQL. For instance, the user table might be something like:
    Code:
    id (int, auto-increment, primary key)
    user_name (varchar)
    site_id (int, foreign key to site table)
    in_use (tinyint [0 = in use, 1 = available])
    
    (You'd probably have a unique index on the combined user_name/site_id fields.)
    SQL to get $number users for a given site that are available:
    PHP Code:
    $siteID 1;
    $numberNeeded 20;
    $sql "
    SELECT * FROM user 
    WHERE site_id = 
    $sitedID AND available = 1
    ORDER BY user_name LIMIT 
    $numberNeeded
    "

    The same structure could then be used to update the table to change their availability. (You would probably want to use table locking so that both queries could be executed in sequence without worrying about anyone else changing that available status of any users in between the two.)
    PHP Code:
    $sql "
    UPDATE user SET available = 0
    WHERE site_id = 
    $sitedID AND available = 1
    ORDER BY user_name LIMIT 
    $numberNeeded
    "

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2010
    Posts
    32
    Ok that makes sense. So when I do the SQL query, it'll return with an array of only the available users. Likewise it'll have the data in a form on the page, so when it's returned it'll build and array and update the table.

    I've been trying to learn PHP for quite a while so this is the first real world application I'll be building. Thank you for you guidance.

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