Jump to content

Populate Menu


SkyRanger

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/259777-populate-menu/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1331984
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/259777-populate-menu/#findComment-1332173
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.