SkyRanger Posted March 27, 2012 Share Posted March 27, 2012 Hello, I am running into a problem. I am trying to convert : $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM post ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "{$rowyp['year']}<br />"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo " {$rowyp['month']}<br />"; } // output each piece of data under a heading here... echo " {$rowyp['title']}<br />"; } And be able to put it in a javascript tree with very little luck: <ul id="yeartree" class="tree"> <li>{$rowyp['year']} <ul> <li>{$rowyp['month']} <ul> <li>{$rowyp['title']}</li> </ul> </li> </ul> </li> Yes I know the phpcode in the tree is not correct. That is just an example of what I am attempting to do. I can get the tree to display without the js but I need to add it to js due to the amount of entries and need to beable to collapse it. Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/ Share on other sites More sharing options...
grim1208 Posted March 27, 2012 Share Posted March 27, 2012 My friend, here's a quick tutorial using jQuery to accomplish what you're looking for. http://webcloud.se/code/jQuery-Collapse/ Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331478 Share on other sites More sharing options...
SkyRanger Posted March 27, 2012 Author Share Posted March 27, 2012 Thanks grim Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331570 Share on other sites More sharing options...
SkyRanger Posted March 27, 2012 Author Share Posted March 27, 2012 Ok, I have used that before, that is one of the things I have tried. I guess the problem I am running into is the <ul> and placement. That is what seems to be messing everything up. Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331613 Share on other sites More sharing options...
SkyRanger Posted March 27, 2012 Author Share Posted March 27, 2012 ok, after doing some research I have to use nodes. but by the looks at my queryp this will not be possible will it? due to the dates being setup as they are? Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331626 Share on other sites More sharing options...
grim1208 Posted March 27, 2012 Share Posted March 27, 2012 that shouldn't be an issue. i'll look closer at this toward the end of the day if someone else hasn't picked this up and helped you out. i suggest going through your loop where you're querying the data and inide of it build your nodes. Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331641 Share on other sites More sharing options...
SkyRanger Posted March 27, 2012 Author Share Posted March 27, 2012 thanks grim, I am fighting with it right now trying to figure things out. Not having much luck Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331713 Share on other sites More sharing options...
SkyRanger Posted March 28, 2012 Author Share Posted March 28, 2012 Does anybody have any idea on how I would be able to do this. I am having a problem with the display part of it. As you can see with the code here: $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM post ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "{$rowyp['year']}<br />"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo " {$rowyp['month']}<br />"; } // output each piece of data under a heading here... echo " {$rowyp['title']}<br />"; } [code] I can get it to look like a tree. But now I need it to go into a collapsible tree and am having problem with the layout where the <li> are required to go. I am not sure if I am going to require to convert this over somehow to nodes or if there is another way I am able to do this. Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331984 Share on other sites More sharing options...
SkyRanger Posted March 29, 2012 Author Share Posted March 29, 2012 Got it to sort of work. I like it using jquery. If anybody is interested here is what I did: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> function showonlyone(thechosenone) { $('div[name|="newboxes"]').each(function(index) { if ($(this).attr("id") == thechosenone) { $(this).show(200); } else { $(this).hide(600); } }); }</script> <?php mysql_connect(..... mysql_select_db("database") or die(mysql_error()); $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM post ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "<b>{$rowyp['year']}</b><br />"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo "<a id=\"myHeader{$rowyp['month']}\" href=\"javascript:showonlyone('newboxes[b]{$rowyp['month']}{$rowyp['year']}[/b]');\">{$rowyp['month']}</a><br>"; } // output each piece of data under a heading here... echo "<div name=\"newboxes\" id=\"newboxes[b]{$rowyp['month']}{$rowyp['year']}[/b]\">{$rowyp['title']}</div>"; } $rowyp['month']}{$rowyp['year']} <--- This is required incase you have the same month but different years. Quote Link to comment https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1332173 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.