The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
Here's something I need help on :
PHP Code:
Is there anyway I can change things around to optimize what I am trying to do ? My logic for the code above is: I get the parent categories first ( those with parentcategory=0 meaning they are the parent categories already ), and for each of those parentcategories, query again for those categories whose parentcategory = the id of those parent categories. Obviously this isn't as efficient as it can be. As it is, this is probably the code portion contributing to the massive amount of queries on the page. Any help would be most appreciated. |
#2
|
||||
|
||||
![]()
A possible solution was offered by rake here, but I don't quite get it.
A solution could potentially teach me how to deal with handling queries in nested while loops ( which I keep using now in most of my hacks because I do not know otherwise ..... ) Could anyone take the time to explain this to me or offer a better solution to my code, please ? Thanks ! ![]() |
#3
|
||||
|
||||
![]()
You're best off storing a cache of the subcategories in your article_category table
![]() |
#4
|
||||
|
||||
![]()
I don't understand Dean
![]() |
#5
|
||||
|
||||
![]()
Ok do you know how serialization works? Basically when managing your categories from the admincp you run a query like this:
[sql] SELECT categoryid, title FROM category_table WHERE parentid = $categorid [/sql] Then look through it like so: PHP Code:
|
#6
|
||||
|
||||
![]()
Still not too sure what you mean, even after going through php.net's serialize function.
Will read up more on this first, thanks for pointing me in some direction ![]() |
#7
|
||||
|
||||
![]()
Well basically it takes an array and stores it as a string. You can place the string in the database and then unserialize it back into an array once you've pulled it back out the database. vB3 uses it in a lot of places so it's a good idea to read up a bit on how it works
![]() Just write a test script: PHP Code:
|
#8
|
||||
|
||||
![]()
take a look at that code, that should do what your code di, but just using one query:
PHP Code:
|
#9
|
||||
|
||||
![]()
It works ! Thanks Stefan
![]() But to understand the code better, could you explan what this bit does : PHP Code:
![]() p.s. 36->11queries, 41->13queries, woot ! ![]() |
#10
|
||||
|
||||
![]()
the $cat_cache array is a cache of all categories you have or better its an array of arrays of categories and looks like that:
$cat_cache 0 => array of categories with the parentid 0 1 => array of categories with the parentid 1 and so on. |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|