Formatting a multi-level menu using only one query

By crisp on Sunday 23 December 2007 23:46 - Comments (8)
Category: PHP, Views: 2726

In the programming forum (dutch) on Gathering of Tweakers I often see people struggeling with multi-level menu's stored in a database and the formatting of such menu in HTML.

This is actually quite a common programming problem that can be solved using some kind of recursion or stack-based processing in order to create a tree out of a flat datastructure containing parent-child relations. However, in most cases the final solution that is presented involves seperate queries being executed inside a loop or inside a function that is called recursively which retrieves the child-elements for a specific parent. In situations where the menu has many items and/or has many levels this could easily result in dozens of queries being executed only to generate something simple as a treelike-output.

I would like to show you how this can be done using only a single query.

Read more »

Is 100.000 times match() enough for you?

By crisp on Sunday 18 March 2007 02:49 - Comments (0)
Category: PHP, Views: 489

PHP 5.2 now comes with 2 new .ini directives:

code:
1
2
3
[Pcre]
;pcre.recursion_limit=100000
;pcre.backtrack_limit=100000


Although default disabled PHP will still force these defaults onto PCRE which will cause failure on common regular expressions fed on content that has more than 100.000 bytes.

Actually these settings map to PCRE's MATCH_LIMIT and MATCH_LIMIT_RECURSION directives, none of which have actually anything to do with backtracking in particular and which within PCRE are set to 10.000.000 by default...

update 23/12/2007: http://bugs.php.net/bug.php?id=40846 is the filed bugreport and this problem is still current.