0

Hello,

I am just after some information if anyone knows how to create a system in php that auto assigns a user at random when a record is logged in a mysql database

I have been tasked to build a logging system for which uses a database to store the data but auto assigns users based on a user data database of arround three users to start with, so each time you log a new call is auto assigns a differnet user, this is so each call gets allocated correcly

Does anyone know how I can achieve this

Thanks,
Martin

3
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by urbanthistleuk
0

Maybe...

INSERT INTO table (field1, field2, user_id) VALUES('$field1', '$field2',(SELECT user_id FROM users ORDER BY RAND() LIMIT 1))

However ORDER BY RAND() can be notoriously slow on larger tables.

Edited by diafol

0

I wonder why you would use a random assignment if the goal is to get a correct allocation. I'd count the number of assignments for each user and assign the one with the least. To make it simple just add a column to the user table and keep that updated.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.