At 7/5/2002, you wrote: > >I'm working on a way to pull menus/pages from a database. Currently I have > >this working on 2 levels - Topic headers & actual page titles - & it prints > >it out fairly nice & doesn't take long to load. What I need to do is add a > >level between the 2, a sub-header. > > > >I'm running both the apache server & mysql server on the same linux box as > >the current load isn't very high. I'm wondering whether it would be > >better/easier to Load all the topic headers into an array, then any possible > >sub-headers into a 2nd array, then the pages into a 3rd array (or even into > >a multidimensional array?). Then go through the arrays & match the pages. > >Or would it be easier to write 1 huge SQL statement & have the SQL server > >run the whole query? > >*ANY* time you can sort/search in SQL, or you can do it in PHP, the SQL way >will be faster. > >I'm sure there's an exception to this rule, but I've never seen it :-)
Hi, I have here a beta of my gallery software (normalized to fourth normal form and good use of indexes) where I did a user-selectable limit where you decide if pagination and sorting (SORT BY and ORDER by) are done by PHP or by MySQL. Especially ORDER BY is quite slow compared to other SQL commands and optimizing it may not always be easy: http://www.mysql.com/doc/O/R/ORDER_BY_optimisation.html In Apache/MySQL under Windows XP the difference is small result sets is quite big (e.g. 0.07s vs. 0.12s), and in Linux box it is much smaller but still noticeable. When result set gets bigger MySQL gains speed. The MySQL method also varies more in speed. So, offer a "treshold" value choice from "use always PHP" to "use always SLQ" and few steps in between, because there is no way of knowing which way works best in each server and image amount, without testing it. Also, many virtual hosts share MySQL server(s), so offering a choice to use PHP for pagination and sorting on "own server RAM/CPU" may by beneficial. I also believe that anything that produces less load to MySQL is good. This is just my experience: I believe in empirical research :) Pekka ------------------------- Pekka Saarinen http://photography-on-the.net ------------------------- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php