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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.