shockuk
12-05-2005, 04:56 PM
Hi all,
I'm developing a forum-style script, and have hit a problem. I'd like to make it run really fast, so i'm trying to use as little MySQL queries as possible.
When a whole thread is listed (i.e. multiple posts), the script first grabs the content of each post from my "posts" table (this includes the user's ID).
Each user can include a little information about themselves, such as location, avatar, postcount, etc. These fields are in the "users" table.
For each post that's listed, the script looks at the UserID of who created the post. It then grabs the user's information from the user table.
An example of how to do this, would be similar to the following pseudo code:
-Grab posts where thread-id = whatever
-loop through all rows (posts)
-Grab user where user id = creator of post
-Show user information and post
Obviously the above method uses LOADS of queries, and i'd like to use as little as possible.
I have tried using a 'WHERE OR' clause to do this, however obviously when a user posts in the same thread twice then things get messed up (for example, WHERE id='3' OR id='3') only returns one result.
I hope I explained this OK,
If anyone has any ideas of how to achieve this (e.g. how is it done in VB and SMF) any help would be greatly appreciated.
Thanks.
I'm developing a forum-style script, and have hit a problem. I'd like to make it run really fast, so i'm trying to use as little MySQL queries as possible.
When a whole thread is listed (i.e. multiple posts), the script first grabs the content of each post from my "posts" table (this includes the user's ID).
Each user can include a little information about themselves, such as location, avatar, postcount, etc. These fields are in the "users" table.
For each post that's listed, the script looks at the UserID of who created the post. It then grabs the user's information from the user table.
An example of how to do this, would be similar to the following pseudo code:
-Grab posts where thread-id = whatever
-loop through all rows (posts)
-Grab user where user id = creator of post
-Show user information and post
Obviously the above method uses LOADS of queries, and i'd like to use as little as possible.
I have tried using a 'WHERE OR' clause to do this, however obviously when a user posts in the same thread twice then things get messed up (for example, WHERE id='3' OR id='3') only returns one result.
I hope I explained this OK,
If anyone has any ideas of how to achieve this (e.g. how is it done in VB and SMF) any help would be greatly appreciated.
Thanks.
