Re: [PHP] Reuse MySQL prepared statement
> I would recommend using using a preorder tree traversal for storing > the data. It is a little different at first, but once you get the > idea it is pretty slick to work with. The main advantage is to build > the tree structure you only need one query as opposed to a recursive > algorithm. This Tree thang doesn't use recursion, and only one query. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.phpguru.org/RGraph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reuse MySQL prepared statement
Eric Butera wrote: > On Mon, Sep 29, 2008 at 11:21 AM, Richard Heyes <[EMAIL PROTECTED]> wrote: >>> Use a tree structure (I assume it's a tree type menu that has already >>> been written and save yourself the hassle. The PEAR HTML_TreeMenu code >>> can Create a tree structure from a Tree object (my own tree class at >>> phpguru.org). >> Sorry, forgot to mention that said Tree object can create a tree >> structure from a flat MySQL result set using the familiar, >> id/parent_id, structure: >> >> >> -- >> Richard Heyes >> > > I would recommend using using a preorder tree traversal for storing > the data. It is a little different at first, but once you get the > idea it is pretty slick to work with. The main advantage is to build > the tree structure you only need one query as opposed to a recursive > algorithm. > > http://www.sitepoint.com/article/hierarchical-data-database/2/ > http://dev.mysql.com/tech-resources/articles/hierarchical-data.html I will keep the preorder tree traversal in mind, however, I am currently not worried about the number of queries. I just cannot figure out how to reuse the existing prepared statement. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reuse MySQL prepared statement
On Mon, Sep 29, 2008 at 11:21 AM, Richard Heyes <[EMAIL PROTECTED]> wrote: >> Use a tree structure (I assume it's a tree type menu that has already >> been written and save yourself the hassle. The PEAR HTML_TreeMenu code >> can Create a tree structure from a Tree object (my own tree class at >> phpguru.org). > > Sorry, forgot to mention that said Tree object can create a tree > structure from a flat MySQL result set using the familiar, > id/parent_id, structure: > > > -- > Richard Heyes > > HTML5 Graphing for FF, Chrome, Opera and Safari: > http://www.phpguru.org/RGraph > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I would recommend using using a preorder tree traversal for storing the data. It is a little different at first, but once you get the idea it is pretty slick to work with. The main advantage is to build the tree structure you only need one query as opposed to a recursive algorithm. http://www.sitepoint.com/article/hierarchical-data-database/2/ http://dev.mysql.com/tech-resources/articles/hierarchical-data.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reuse MySQL prepared statement
> Use a tree structure (I assume it's a tree type menu that has already > been written and save yourself the hassle. The PEAR HTML_TreeMenu code > can Create a tree structure from a Tree object (my own tree class at > phpguru.org). Sorry, forgot to mention that said Tree object can create a tree structure from a flat MySQL result set using the familiar, id/parent_id, structure: -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.phpguru.org/RGraph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reuse MySQL prepared statement
> I am trying to use a prepared MySQL statement after retrieving the > results from a previous query (it's for a multi-level menu). The first > query works fine, but the second query does not. Use a tree structure (I assume it's a tree type menu that has already been written and save yourself the hassle. The PEAR HTML_TreeMenu code can Create a tree structure from a Tree object (my own tree class at phpguru.org). -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.phpguru.org/RGraph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Reuse MySQL prepared statement
I am trying to use a prepared MySQL statement after retrieving the results from a previous query (it's for a multi-level menu). The first query works fine, but the second query does not. I have tried using mysqli_stmt::reset and mysqli_stmt::close, but had no luck with those either. Lastly, the only time I receive error messages is when I use mysqli_stmt::close. The code I am currently using is: [code] $l1_parent = 0; $retrieve_menu->bind_param("i", $l1_parent); $retrieve_menu->execute(); $retrieve_menu->bind_result($menu_id, $menu_item, $menu_cmd); $level1 = array(); while ($retrieve_menu->fetch()) { $level1_item = array(); array_push($level1_item, $menu_id); array_push($level1_item, $menu_item); array_push($level1_item, $menu_cmd); array_push($level1, $level1_item); } $retrieve_menu->free_result(); $level1_counter = 0; echo ""; for ($level1_counter = 0; count($level1) >= $level1_counter; $level1_counter++) { echo "https://myserver/?sid=$GENSID&uid=$GETUID&cmd="; . $level1[$level1_counter][2] . "\" class=\"" . $level1[$level1_counter][2] . "\">" . $level1[$level1_counter][1] . ""; $l2_parent = $level1[$level1_counter][0]; $retrieve_menu->bind_param("i", $l2_parent); $retrieve_menu->execute(); $retrieve_menu->bind_result($menu_id, $menu_item, $menu_cmd); $level2 = array(); while ($retrieve_menu->fetch()) { $level2_item = array(); array_push($level2_item, $menu_id); array_push($level2_item, $menu_item); array_push($level2_item, $menu_cmd); array_push($level2, $level2_item); } $retrieve_menu->close(); if (count($level2) > 0) { echo ""; echo "$level2 " . $level1[$level1_counter][0] . ""; echo ""; } } echo ""; [/code] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php