james182 Posted January 14, 2009 Share Posted January 14, 2009 I need to get this from pulling data from a directory to generating it from a Database. my Database: tbl_tree_menu treeview_id | treeview_name | treeview_desc | treeview_parent_id ------------------------------------------------------------------- 1 | root | folder | 0 ------------------------------------------------------------------- 2 | 1. Parent | folder | 1 ------------------------------------------------------------------- 3 | 2. Parent | folder | 1 ------------------------------------------------------------------- 4 | 1. Child P1 | folder | 2 ------------------------------------------------------------------- 5 | 2. Child P1 | folder | 2 ------------------------------------------------------------------- 6 | My Doc PC1 | document | 4 ------------------------------------------------------------------- <?php $_POST['dir'] = urldecode($_POST['dir']); if( file_exists($root . $_POST['dir']) ) { $files = scandir($root . $_POST['dir']); natcasesort($files); if( count($files) > 2 ) { /* The 2 accounts for . and .. */ echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; // All dirs foreach( $files as $file ) { if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_POST['dir'] . $file) ) { echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>"; } } // All files foreach( $files as $file ) { if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) { $ext = preg_replace('/^.*\./', '', $file); echo "<li class=\"file ext_$ext\"><a href=\"#\" id=\"1\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>"; } } echo "</ul>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/ Share on other sites More sharing options...
trq Posted January 14, 2009 Share Posted January 14, 2009 And where exactly are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736654 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 In coverting it to get the data from my DB instead of directory.. removing the below: $_POST['dir'] = urldecode($_POST['dir']); if( file_exists($root . $_POST['dir']) ) { $files = scandir($root . $_POST['dir']); natcasesort($files); And Replace with something like this: global $link; $query = "SELECT * FROM tbl_tree_menu WHERE treeview_parent_id = '$treeview_parent_id' "; $result = mysql_query($query, $link) or die(mysql_error()); // Change for your database Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736676 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 Please Help... This has me confused. Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736702 Share on other sites More sharing options...
uniflare Posted January 14, 2009 Share Posted January 14, 2009 Seems we need more information; Am i correct in saying you have an existing database saved in flat-file text format? Also that you want to put that database into a mysql table and read from mysql instead? You would first need to create a database for your tables. Then create the tables with the field names for your data. Then you can add your database, and start reading from it. --edit: Upon further examination of your original question, do you want this script to save its results to mysql, so you can recall it and maybe do some comparison checks for changes in file structure? Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736724 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 The DB table "tbl_tree_menu" above is the one the i have already created with data in it. The directory tree code above is for creating a tree menu from a folder dir no DB required. What i need is for the data in my DB to be displyed in the tree menu format. No saving for recall just displaying what is in the DB in a tree menu. Below is all the code to create the tree menu. This should be plenty for you now. Here is the dump of my DB: CREATE TABLE tbl_tree_menu ( treeview_id int(11) NOT NULL auto_increment, treeview_name varchar(155) NOT NULL, treeview_desc varchar(155) NOT NULL, treeview_parent_id int(11) NOT NULL, PRIMARY KEY (treeview_id) ) TYPE=MyISAM AUTO_INCREMENT=74 ; -- -- Dumping data for table 'tbl_tree_menu' -- INSERT INTO tbl_tree_menu (treeview_id, treeview_name, treeview_desc, treeview_parent_id) VALUES (1, 'root', 'folder', 0), (2, '1. Corporate', 'folder', 1), (3, '2. Divisional', 'folder', 1), (4, '1. Systems', 'folder', 2), (5, '2. Policies', 'folder', 2), (6, '3. Processes', 'folder', 2), (7, '4. Quality Assurance', 'folder', 2), (8, '5. Risk Management', 'folder', 2), (9, '6. Administration', 'folder', 2), (10, '1. Standards', 'folder', 7), (11, '2. Guidelines', 'folder', 7), (12, '3. Templates', 'folder', 7), (13, '4. Forms', 'folder', 7), (14, '5. Registers', 'folder', 7), (15, '1. Standards', 'folder', , (16, '2. Guidelines', 'folder', , (17, '3. Templates', 'folder', , (18, '4. Forms', 'folder', , (19, '5. Registers', 'folder', , (20, '1. General Administration', 'folder', 9), (21, '2. Human Resources', 'folder', 9), (22, '3. WH&S', 'folder', 9), (23, '4. Finance', 'folder', 9), (24, '5. IT', 'folder', 9), (25, '6. Legal', 'folder', 9), (26, '1. Civil', 'folder', 3), (27, '2. Structural', 'folder', 3), (28, '3. Hydraulic', 'folder', 3), (29, '4. Building', 'folder', 3), (30, '5. Telco', 'folder', 3), (31, '6. Project Management', 'folder', 3), (32, '7. Drafting', 'folder', 3), (33, '8. Cross Divisional General', 'folder', 3), (34, '1. Standards', 'folder', 26), (35, '2. Guidelines', 'folder', 26), (36, '3. Templates', 'folder', 26), (37, '4. Forms', 'folder', 26), (38, '5. Register', 'folder', 26), (39, '1. Standards', 'folder', 27), (40, '2. Guidelines', 'folder', 27), (41, '3. Templates', 'folder', 27), (42, '4. Forms', 'folder', 27), (43, '5. Registers', 'folder', 27), (44, '1. Standards', 'folder', 28), (45, '2. Guidelines', 'folder', 28), (46, '3. Templates', 'folder', 28), (47, '4. Forms', 'folder', 28), (48, '5. Registers', 'folder', 28), (49, '1. Standards', 'folder', 29), (50, '2. Guidelines', 'folder', 29), (51, '3. Templates', 'folder', 29), (52, '4. Forms', 'folder', 29), (53, '5. Registers', 'folder', 29), (54, '1. Standards', 'folder', 30), (55, '2. Guidelines', 'folder', 30), (56, '3. Templates', 'folder', 30), (57, '4. Forms', 'folder', 30), (58, '5. Registers', 'folder', 30), (59, '1. Standards', 'folder', 31), (60, '2. Guidelines', 'folder', 31), (61, '3. Templates', 'folder', 31), (62, '4. Forms', 'folder', 31), (63, '5. Registers', 'folder', 31), (64, '1. Standards', 'folder', 32), (65, '2. Guidelines', 'folder', 32), (66, '3. Templates', 'folder', 32), (67, '4. Forms', 'folder', 32), (68, '5. Registers', 'folder', 32), (69, '1. Standards', 'folder', 33), (70, '2. Guidelines', 'folder', 33), (71, '3. Templates', 'folder', 33), (72, '4. Forms', 'folder', 33), (73, '5. Registers', 'folder', 33); Head JS: $(document).ready( function() { $('#fileTree').fileTree({ root: '_documents/' }, function(file) { //alert(file); openFile(file); }); }); Page Code: <div id="fileTree" class="demo"></div> JS File (jqueryFileTree.js): // jQuery File Tree Plugin // // Version 1.01 // Usage: $('.fileTreeDemo').fileTree( options, callback ) // // Options: root - root folder to display; default = / // script - location of the serverside AJAX file to use; default = jqueryFileTree.php // folderEvent - event to trigger expand/collapse; default = click // expandSpeed - default = 500 (ms); use -1 for no animation // collapseSpeed - default = 500 (ms); use -1 for no animation // expandEasing - easing function to use on expand (optional) // collapseEasing - easing function to use on collapse (optional) // multiFolder - whether or not to limit the browser to one subfolder at a time // loadMessage - Message to display while initial tree loads (can be HTML) // // if(jQuery) (function($){ $.extend($.fn, { fileTree: function(o, h) { // Defaults if( !o ) var o = {}; if( o.root == undefined ) o.root = '_documents/'; if( o.script == undefined ) o.script = 'http://localhost/mySite/jqueryFileTree.php'; if( o.folderEvent == undefined ) o.folderEvent = 'click'; if( o.expandSpeed == undefined ) o.expandSpeed= 500; if( o.collapseSpeed == undefined ) o.collapseSpeed= 500; if( o.expandEasing == undefined ) o.expandEasing = null; if( o.collapseEasing == undefined ) o.collapseEasing = null; if( o.multiFolder == undefined ) o.multiFolder = false; if( o.loadMessage == undefined ) o.loadMessage = 'Loading...'; $(this).each( function() { function showTree(c, t) { $(c).addClass('wait'); $(".jqueryFileTree.start").remove(); $.post(o.script, { dir: t }, function(data) { $(c).find('.start').html(''); $(c).removeClass('wait').append(data); if( o.root == t ) $(c).find('UL:hidden').show(); else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing }); bindTree(c); }); } function bindTree(t) { $(t).find('LI A').bind(o.folderEvent, function() { if( $(this).parent().hasClass('directory') ) { if( $(this).parent().hasClass('collapsed') ) { // Expand if( !o.multiFolder ) { $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed'); } $(this).parent().find('UL').remove(); // cleanup showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) ); $(this).parent().removeClass('collapsed').addClass('expanded'); } else { // Collapse $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); $(this).parent().removeClass('expanded').addClass('collapsed'); } } else { h($(this).attr('rel')); } return false; }); // Prevent A from triggering the # on non-click events if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; }); } // Loading message $(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>'); // Get the initial file list showTree( $(this), escape(o.root) ); }); } }); })(jQuery); PHP Code: <?php $_POST['dir'] = urldecode($_POST['dir']); if( file_exists($root . $_POST['dir']) ) { $files = scandir($root . $_POST['dir']); natcasesort($files); if( count($files) > 2 ) { // The 2 accounts for . and .. echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; // All dirs foreach( $files as $file ) { if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_POST['dir'] . $file) ) { echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>"; } } // All files foreach( $files as $file ) { if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) { $ext = preg_replace('/^.*\./', '', $file); echo "<li class=\"file ext_$ext\"><a href=\"#\" id=\"1\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>"; } } echo "</ul>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736738 Share on other sites More sharing options...
uniflare Posted January 14, 2009 Share Posted January 14, 2009 I see, it should just be a case of editing the php file. Could you give us the html output of this tree menu? as seen in the browser's "View Source" feature. This way I should have a better understanding of the required format. At the moment, to me it looks like you print out all the directories and _then_ all the files regardless of which file belongs to which directory - I'm sure that's not the case, hopefully the output should help with this. (Don't visit the page with the Javascript on, visit the actual php file in a browser). Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736743 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php print $title; ?></title> <link rel="stylesheet" type="text/css" href="css/jqueryFileTree.css"> <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script> <script type="text/javascript" src="js/jqueryFileTree.js"></script> <script type="text/javascript" language="JavaScript"> $(document).ready( function() { $('#fileTree').fileTree({ root: '_documents/' }, function(file) { alert(file); //openFile(file); }); }); </script> </head> <body> <div id="fileTree" class="demo"> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="0">root</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="1">1. Corporate</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="2">1. Systems</a></li> <li class="directory collapsed"><a href="#" rel="2">2. Policies</a></li> <li class="directory collapsed"><a href="#" rel="2">3. Processes</a></li> <li class="directory collapsed"><a href="#" rel="2">4. Quality Assurance</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="7">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="7">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="7">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="7">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="7">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="2">5. Risk Management</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="8">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="8">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="8">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="8">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="8">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="2">6. Administration</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="9">1. General Administration</a></li> <li class="directory collapsed"><a href="#" rel="9">2. Human Resources</a></li> <li class="directory collapsed"><a href="#" rel="9">3. WH&S</a></li> <li class="directory collapsed"><a href="#" rel="9">4. Finance</a></li> <li class="directory collapsed"><a href="#" rel="9">5. IT</a></li> <li class="directory collapsed"><a href="#" rel="9">6. Legal</a></li> </ul> </li> </ul> </li> <li class="directory collapsed"><a href="#" rel="1">2. Divisional</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="3">1. Civil</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="26">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="26">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="26">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="26">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="26">5. Register</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">2. Structural</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="27">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="27">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="27">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="27">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="27">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">3. Hydraulic</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="28">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="28">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="28">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="28">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="28">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">4. Building</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="29">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="29">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="29">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="29">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="29">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">5. Telco</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="30">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="30">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="30">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="30">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="30">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">6. Project Management</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="31">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="31">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="31">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="31">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="31">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">7. Drafting</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="32">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="32">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="32">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="32">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="32">5. Registers</a></li> </ul> </li> <li class="directory collapsed"><a href="#" rel="3">8. Cross Divisional General</a> <ul class="jqueryFileTree"> <li class="directory collapsed"><a href="#" rel="33">1. Standards</a></li> <li class="directory collapsed"><a href="#" rel="33">2. Guidelines</a></li> <li class="directory collapsed"><a href="#" rel="33">3. Templates</a></li> <li class="directory collapsed"><a href="#" rel="33">4. Forms</a></li> <li class="directory collapsed"><a href="#" rel="33">5. Registers</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736760 Share on other sites More sharing options...
uniflare Posted January 14, 2009 Share Posted January 14, 2009 The php file code you gave, and the output html you posted are inconsistent. Is the php in a loop of some kind? That php code cannot generate that html output, are you sure you got all the necessary code? Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736775 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 <div id="fileTree" class="demo"></div> This is what the html outputs, not the other. sorry about that Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736783 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 I have attached a file to make it easier. the attached is the code i am trying to get to output the items from a DB. Not from folder Directory. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736786 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 i have supplied all the info i can think of for some one to help get the working. Please help ... Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-736884 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 Sorry i really need this to work. Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737205 Share on other sites More sharing options...
trq Posted January 14, 2009 Share Posted January 14, 2009 the attached is the code i am trying to get to output the items from a DB. Not from folder Directory. I don't see any code where you have tried to get this working with a database. Were not here to write code for people. Can we see the code where you are actually stuck? Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737251 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 ok here is my code. this replaces the code in the jqueryFileTree.php. <?php /***************************************** DB CONNECT **************************************************/ $dbhost="localhost"; $dbuser="user"; $dbpass="pass"; $dbname="DB_name"; ($link = mysql_pconnect("$dbhost", "$dbuser", "$dbpass")) || die("Couldn't connect to MySQL"); mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() ); /*************************************************************************************************************/ $query = "SELECT * FROM tbl_tree_menu"; $result = mysql_query($query, $link) or die("TreeMenu fatal error: ".mysql_error()); echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; while($r = mysql_fetch_array($result)){ $treeview_id = $r["treeview_id"]; $treeview_name = $r["treeview_name"]; $treeview_desc = $r["treeview_desc"]; $treeview_parent_id = $r["treeview_parent_id"]; echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"".$treeview_parent_id."\">" . $treeview_name . "</a></li>"; } while($r = mysql_fetch_array($result)){ $treeview_id = $r["treeview_id"]; $treeview_name = $r["treeview_name"]; $treeview_desc = $r["treeview_desc"]; $treeview_ext = $r["treeview_ext"]; $treeview_parent_id = $r["treeview_parent_id"]; echo "<li class=\"file ext_".$treeview_ext."\"><a href=\"#\" id=\"".$treeview_id."\" rel=\"" . $treeview_parent_id . "\">" . $treeview_name . "</a></li>"; } echo "</ul>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737303 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 Aiming for: root - 1. Corporate -- 1. Sysytems -- 2. Policies -- 3. etc ... -2. Divisional -- 1. Standards -- 2. Guidelines -- 3. Forms -- 4. etc ... my Updated code: while ($r = mysql_fetch_array($result)) { echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; $mainMenu = mysql_query("SELECT * FROM tbl_treeview WHERE treeview_id = ".$r['treeview_id'].""); while ($subMenu = mysql_fetch_array($mainMenu) ) { $report = mysql_query("SELECT * FROM tbl_treeview WHERE treeview_parent_id = ".$r['treeview_id']." "); echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"".$r['treeview_parent_id']."\">" . $r['treeview_name'] . "</a></li>"; while ($reportrow = mysql_fetch_array($report) ) { echo "<ul>"; echo "<li class=\"file ext_".$r["treeview_ext"]."\"><a href=\"#\" id=\"".$r["treeview_id"]."\" rel=\"" . $r["treeview_parent_id"] . "\">" . $r["treeview_name"] . "</a></li>"; echo "</ul>"; } echo "</li></ul>"; } echo "</li></ul>"; } Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737325 Share on other sites More sharing options...
james182 Posted January 14, 2009 Author Share Posted January 14, 2009 Updated Code I am now stuck on getting this to work Correctly <?php /***************************************** DB CONNECT **************************************************/ $dbhost="localhost"; $dbuser="user"; $dbpass="pass"; $dbname="my_db"; ($link = mysql_pconnect("$dbhost", "$dbuser", "$dbpass")) || die("Couldn't connect to MySQL"); mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() ); /*************************************************************************************************************/ $query = "SELECT * FROM tbl_tree_menu"; $result = mysql_query($query, $link) or die("TreeMenu fatal error: ".mysql_error()); echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; while ($topData = mysql_fetch_array($result)) { $mainMenu = mysql_query("SELECT * FROM tbl_treeview WHERE treeview_id = ".$topData['treeview_parent_id'].""); echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"".$topData['treeview_parent_id']."\">" . $topData['treeview_name'] . "</a>"; while ($subdata = mysql_fetch_array($mainMenu) ) { $subMenu = mysql_query("SELECT * FROM tbl_treeview WHERE treeview_id = ".$topData['treeview_parent_id']." "); echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"".$subdata['treeview_parent_id']."\">" . $subdata['treeview_name'] . "</a>"; while ($subSubData = mysql_fetch_array($subMenu) ) { echo "<ul>"; echo "<li class=\"file ext_".$subSubData["treeview_ext"]."\"><a href=\"#\" id=\"".$subSubData["treeview_id"]."\" rel=\"" . $subSubData["treeview_parent_id"] . "\">" . $subSubData["treeview_name"] . "</a></li>"; echo "</ul>"; } echo "</li></ul>"; } echo "</li></ul>"; } echo "</ul>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737355 Share on other sites More sharing options...
uniflare Posted January 15, 2009 Share Posted January 15, 2009 good job getting this far, ok so ouve sort of got the idea, whats the output html of this one? we can compare it with the post u gave me earlier and see what needs to be changed . you might want to try in small steps first, likie a single folder, then ou can add to it so it loops through all the subfolers of that foler, then u can make it recursive, so it goes through every subdirectory until it has no more. it will be easier to work and and understand. Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737579 Share on other sites More sharing options...
james182 Posted January 15, 2009 Author Share Posted January 15, 2009 Ok I have managed to get it to list the tree structure properly from the DB with nested while loops. Now I have the problem of the menu not working properly. Will post the entire code to get this resolved. (post in 1hr 30min). Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737839 Share on other sites More sharing options...
james182 Posted January 15, 2009 Author Share Posted January 15, 2009 Ok here is the full code, folder attached. i have the output from the DB done but the tree menu still wont operate correctly. Run it and see. CREATE TABLE tbl_tree_menu ( treeview_id int(11) NOT NULL auto_increment, treeview_name varchar(155) NOT NULL, treeview_desc varchar(155) NOT NULL, treeview_ext varchar(4) NOT NULL, treeview_parent_id int(11) NOT NULL, PRIMARY KEY (treeview_id) ) TYPE=MyISAM AUTO_INCREMENT=79 ; -- -- Dumping data for table 'tbl_treeview' -- INSERT INTO tbl_tree_menu (treeview_id, treeview_name, treeview_desc, treeview_ext, treeview_parent_id) VALUES (1, 'root', 'folder', '', 0), (2, '1. Corporate', 'folder', '', 1), (3, '2. Divisional', 'folder', '', 1), (4, '1. Systems', 'folder', '', 2), (5, '2. Policies', 'folder', '', 2), (6, '3. Processes', 'folder', '', 2), (7, '4. Quality Assurance', 'folder', '', 2), (8, '5. Risk Management', 'folder', '', 2), (9, '6. Administration', 'folder', '', 2), (10, '1. Standards', 'folder', '', 7), (11, '2. Guidelines', 'folder', '', 7), (12, '3. Templates', 'folder', '', 7), (13, '4. Forms', 'folder', '', 7), (14, '5. Registers', 'folder', '', 7), (15, '1. Standards', 'folder', '', , (16, '2. Guidelines', 'folder', '', , (17, '3. Templates', 'folder', '', , (18, '4. Forms', 'folder', '', , (19, '5. Registers', 'folder', '', , (20, '1. General Administration', 'folder', '', 9), (21, '2. Human Resources', 'folder', '', 9), (22, '3. WH&S', 'folder', '', 9), (23, '4. Finance', 'folder', '', 9), (24, '5. IT', 'folder', '', 9), (25, '6. Legal', 'folder', '', 9), (26, '1. Civil', 'folder', '', 3), (27, '2. Structural', 'folder', '', 3), (28, '3. Hydraulic', 'folder', '', 3), (29, '4. Building', 'folder', '', 3), (30, '5. Telco', 'folder', '', 3), (31, '6. Project Management', 'folder', '', 3), (32, '7. Drafting', 'folder', '', 3), (33, '8. Cross Divisional General', 'folder', '', 3), (34, '1. Standards', 'folder', '', 26), (35, '2. Guidelines', 'folder', '', 26), (36, '3. Templates', 'folder', '', 26), (37, '4. Forms', 'folder', '', 26), (38, '5. Register', 'folder', '', 26), (39, '1. Standards', 'folder', '', 27), (40, '2. Guidelines', 'folder', '', 27), (41, '3. Templates', 'folder', '', 27), (42, '4. Forms', 'folder', '', 27), (43, '5. Registers', 'folder', '', 27), (44, '1. Standards', 'folder', '', 28), (45, '2. Guidelines', 'folder', '', 28), (46, '3. Templates', 'folder', '', 28), (47, '4. Forms', 'folder', '', 28), (48, '5. Registers', 'folder', '', 28), (49, '1. Standards', 'folder', '', 29), (50, '2. Guidelines', 'folder', '', 29), (51, '3. Templates', 'folder', '', 29), (52, '4. Forms', 'folder', '', 29), (53, '5. Registers', 'folder', '', 29), (54, '1. Standards', 'folder', '', 30), (55, '2. Guidelines', 'folder', '', 30), (56, '3. Templates', 'folder', '', 30), (57, '4. Forms', 'folder', '', 30), (58, '5. Registers', 'folder', '', 30), (59, '1. Standards', 'folder', '', 31), (60, '2. Guidelines', 'folder', '', 31), (61, '3. Templates', 'folder', '', 31), (62, '4. Forms', 'folder', '', 31), (63, '5. Registers', 'folder', '', 31), (64, '1. Standards', 'folder', '', 32), (65, '2. Guidelines', 'folder', '', 32), (66, '3. Templates', 'folder', '', 32), (67, '4. Forms', 'folder', '', 32), (68, '5. Registers', 'folder', '', 32), (69, '1. Standards', 'folder', '', 33), (70, '2. Guidelines', 'folder', '', 33), (71, '3. Templates', 'folder', '', 33), (72, '4. Forms', 'folder', '', 33), (73, '5. Registers', 'folder', '', 33), (74, 'MyDocument', 'document', 'doc', 4), (75, 'my Document 2', 'document', 'jpg', 4), (76, 'my Document 3', 'document', 'doc', 4), (77, 'My Testing', 'document', 'xls', 10), (78, 'My Dooda', 'document', 'xml', 10); [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-737893 Share on other sites More sharing options...
james182 Posted January 16, 2009 Author Share Posted January 16, 2009 final stage just need it to open and close properly.... please help this is getting nuts. Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-738779 Share on other sites More sharing options...
uniflare Posted January 18, 2009 Share Posted January 18, 2009 Ok i dont have time atm to help you. but ill give u a tip to let someone else help you. Give them the php code, the html result code from the actual full page, then the html output from JUST the tree menu output, and neatly explain what needs to be different. if you can provide some sort of downloadable file that people can work with, it might help you since they can debug and fix it etc without guessing. Sorry, Thanks and good luck! Quote Link to comment https://forums.phpfreaks.com/topic/140747-database-treemenu-help/#findComment-739877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.