I have a feature in my webstie that the users can receive items.
I have a table with the list of items and what's the user_id they are belong to - very simple table:
id | user_id | item_id
Sometimes the user may receive an item.
My problem is, that the user can't get the SAME item twice.
so I need to change this query:
$getrandom = mysql_fetch_assoc(mysql_query('SELECT id,name FROM `items` ORDER BY RAND()'));
which gives a random item from all items, instead picking ONLY the items the user don't have (check in the user-item table if he got the item).
I need to filter the items this user has already got. the user id is storred in my session as $_SESSION['id'].
Looking for assistance with this. Thanks in advance!
ON user_items.item_id = items.id
AND user_items.user_id = $_SESSION['id']
WHERE user_items.user_id IS NULL
@theunreal; are you aware that the old mysql_* extension has been deprecated as of version 5.5 of PHP and will very likely be removed from version 5.6 of PHP? You should be migrating over to either the mysqli_* extension or PDO
This topic is now closed. New replies are no longer allowed.