Code: Select all
$r = mysql_query("SELECT id, text, author FROM comments AS c");
while ($c = mysql_fetch_object($r)) {
echo 'Text: ' . htmlentities($c->text;)
$a = mysql_query("SELECT username FROM users WHERE id = {$c->author}"
echo 'Author: ' . htmlentities(mysql_result($a, 0));
}Code: Select all
$r = mysql_query("SELECT c.id, c.text, c.author, u.username FROM comments AS c INNER JOIN users AS u ON u.id = c.author");
while ($c = mysql_fetch_object($r)) {
echo 'Text: ' . htmlentities($c->text;)
echo 'Author: ' . htmlentities($c->username);
}Tha fact is that I noticed that execution time is (exactly I think) the same! Do you know if MySQL do some optimization on accessing always the same table? Maybe it caches the tables index, I don't know... Tell me