View Single Post
06-04-2012, 01:37 PM
#5
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

As a general rule it is best to use one query opposed to two because each query has overhead for execution. Even if one query takes longer than either two it will still run faster than the two combined. It's also better practice, you want your database to do as much of the data processing as possible opposed to having PHP play a part in it. Also, don't use SELECT *, it takes longer to run and leaves ambiguity in your code. Do something like

Code:
SELECT topics.field1, users.field2 [ect]
FROM `forum topics` topics
LEFT JOIN users ON users.id=topics.author
WHERE slug=[$slug]
I wouldn't select from two tables here since you are conditionally joining a second table to a first, that is what JOIN is for.

Thanked by:
Dan (06-04-2012)