/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 04.2011 — If this is database-driven (which it sounds like it [i]should[/i] 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:
<i>
</i>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:
[code=php]
$siteID = 1;
$numberNeeded = 20;
$sql = "
SELECT * FROM user
WHERE site_id = $sitedID AND available = 1
ORDER BY user_name LIMIT $numberNeeded
";
[/code]

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.)
[code=php]
$sql = "
UPDATE user SET available = 0
WHERE site_id = $sitedID AND available = 1
ORDER BY user_name LIMIT $numberNeeded
";
[/code]
Copy linkTweet thisAlerts:
@beatsmithauthorAug 04.2011 — 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.
×

Success!

Help @beatsmith spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...