I have a script that runs a static chatroom(User has to refresh the page manually). When a user submits a post, the user's data(Username, title, user level, etc..) is stored in the DB along with the post.
The script for getting the post looks something like this:
$result = mysql_query("SELECT * FROM Chatroom ORDER by messageid DESC LIMIT 0, 10");
while($message = mysql_fetch_array($result)) {
// Code that takes message and user data like username, rank, etc, and displays it
}
Someone suggested that instead of storing all that data in the social table, I should split it up like this:
$postresult = mysql_query("SELECT * FROM Chatroom ORDER by messageid DESC LIMIT 0, 10");
while($message = mysql_fetch_array($postresult); {
$user_result = mysql_query("SELECT * FROM Members WHERE userid='{$message['userid']}' ");
// code that gets user data and message data from arrays and prints it
}
The second one looks horribly inefficient, because it appears to make 11 queries to the DB. Am I really ignorant about the inner workings of mysql queries, or is this guy messing with me?