Ok say i have 1 table for Users it stores USER_NAME, USER_ID, AND USER_COLOR
and im making a new table for Logs that will store USER_NAME
when viewing a page and i need to recieve this data
i can do 2 querys one for logs and then search users where USER_NAME=USER_NAME
or i can store USER_NAME, USER_ID, AND USER_COLOR all in logs
then i can get all the data with just 1 query.
what would be faster or better?
sample query
$sql = "SELECT id, username, level, namecolor FROM users ORDER BY level DESC";
$query = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($query);
while($row = mysql_fetch_object($query)) {
$Member_id = htmlspecialchars($row->id);
As you are using MySql, your database is a relational one.
This gives you (as you already know) many advantages, so, instead of replicating the user information (already stored in its own table) in other table (logs in this case), you’d better to do
joinswhen needing more information about a user.Let the users information to be in its own table, so, when querying logs data you may do this:
Another point: think what would happen when replicating user info, if you add a new field to the user table (email for instance).