| Conservative Querying | |
|---|---|
| Tweet Topic Started: Jan 27 2009, 05:01 PM (76 Views) | |
| bustya | Jan 27 2009, 05:01 PM Post #1 |
![]()
The Master Bitchslapper
|
The less queries you use, the quicker your task will be accomplished. I've been going back through all of my work and trying to reduce (and reuse) my queries as much as possible. It should also be noted that when possible make the query itself do all the work rather than SELECTING + altering a variable then UPDATING... For instance, if there's some info you'll need about the current user from the usertable, don't write a new query for it. You're already querying the usertable for the current user's info, so in session.php in the checkLogin() function, add additional class variables for the user.
Then, just like with: $user = $session->username; You can: $avatar = $session->avatar; Now, I have a page that deletes an image. Since I allow users to designate any of their pics as their avatar... even a cropped version of a pic, I have to check the usertable for their avatar before I can delete the row in the image table and unset the image from the image folder. I also have a limit of images per user built in, so there's a counter in the usertable called pic_count. Since the user can only delete one image at a time, this is easy WITHIN the query itself.
So, in the code above, I'm reusing the query the basic system uses to get info about the current user and updating the current user's row in the usertable as a part of the process to delete an image and it's row from the image table. Edited by bustya, Jan 27 2009, 05:06 PM.
|
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Other · Next Topic » |






12:49 AM Jul 11