When I go to output users' messages, I like to know which usergroups each member belongs to, because if they belong to 'usergroup A', then I'd like to output this graphic, and if they belong to 'usergroup B', then also add this graphic to their post, etc.
So I have a 'usergroups' table that is so:
Code: Select all
CREATE TABLE usergroups (
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id MEDIUMINT UNSIGNED NOT NULL,
usergroup_id MEDIUMINT UNSIGNED NOT NULL,
PRIMARY KEY (usergroup_id)
);So cutting to the chase, I think I have a code smell in that when I go to output all the users messages, I first call them like so:
Code: Select all
SELECT u.user_id, u.username, u.firstLastName, m.message_id, m.message, m.post_date FROM users AS u, messages AS m WHERE u.user_id=m.user_idCode: Select all
<?php
...
while($resultSet = mysql_fetch_assoc($message_query_result)))
{
$usergroups_query = "SELECT usergroup_id FROM usergroups WHERE user_id={$resultSet['user_id']}";
$usergroups_query_result = @mysql_query($usergroups_query);
....
while ($ug_resultSet = mysql_fetch_assoc($usergroups_query_result)
{
if ($ug_resultSet['usergroup_id'] == '3')
echo 'Usergroup 3 Graphic Here!';
if ($ug_resultSet['usergroup_id'] == '5')
echo 'Usergroup 5 Graphic Here!';
}
}
?>
Any help on this matter would GREATLY be appreciated. Thank you so much.