Jump to content

Help needed - php dynamic menu


howard-moore

Recommended Posts

Hi All,

 

I have a snippet of code (below) which I use to create a dynamic menu from a MySQL database for a community website. Fields used in the database are:

 

ID

parent (what the parent page is)

page_order (what is says on the tin)

short_title (a short title for the page for the URL)

title (the page title - used as the text for the link)

content (the content for the page)

 

I have got the dynamic list to display fine, but what I would like to be able to do is give each list item a 'class' tag when it has been selected (and thus is the page being shown). Can anyone suggest how to amend the below code to allow this?

 

Code is:

 

<!-- ##### START LIST_INFO_PAGES ##### -->
<?php
include("../config/config.php");
?>

<?php
$sql = "SELECT * FROM `PCNET_$filename` WHERE parent = 'council' ORDER BY page_order ASC";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
	print '';
	if ($row["status"]<>'') {
		echo '<li><a href="../council-indiv.php?id=';
		echo ($row["id"]).'&short_title=';
		echo nl2br(stripslashes(utf8_decode($row["short_title"]))).'" title=';
		echo nl2br(stripslashes(utf8_decode($row["title"]))).'>';
		echo nl2br(stripslashes(utf8_decode($row["title"]))).'</a></li>';
	};
};
?>
<!-- ##### END LIST_INFO_PAGES ##### -->

 

Help will be welcome!

Neil

Link to comment
Share on other sites

Hi All - an update!

 

I have added a bit more code to create 'if' / 'else' depending on whether the particular menu list item (i.e. link) has been clicked. This then sets the menu list item to have a specific 'class' attributed to it, which is then coloured a specific colour by the CSS.

 

However, the issue I have is that the particular element I have added (&focus=here), when added to the end of the URL, simply colours all the link button as 'here' buttons:

 

<!-- ##### START LIST_INFO_PAGES ##### -->
<?php
include("../config/config.php");
?>

<?php
$sql = "SELECT * FROM `PCNET_$filename` WHERE parent = 'council' AND type = 'Pages' ORDER BY page_order ASC";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
	print '';
	if ($row["status"]<>'') {
		echo '<li><a href="../council-indiv.php?id=';
		echo ($row["id"]).'&name=';
		echo nl2br(stripslashes(utf8_decode($row["category"]))).'&focus=here" title="';
		echo nl2br(stripslashes(utf8_decode($row["title"]))).'"';
			if	($focus = here) {
				echo ' class="subthere">';
				}
			else {
				echo '>';
				}
		echo nl2br(stripslashes(utf8_decode($row["category"]))).'</a></li>';
	};
};
?>
<!-- ##### END LIST_INFO_PAGES ##### -->

 

Any help would be gratefully received.

 

Neil

Link to comment
Share on other sites

Hmm... didn't seem to work. Perhaps if I give a bit more detail about how the page set-up works:

 

I have a page called council-indiv.php which is the template for the content stored in the MySQL database. The problem with the code that I have found is that if I add a particular string to the URL (such as 'focus=here') it returns ALL the list items that make up the dynamic menu as containing focus=here. Therefore, they all show the css style for a menu item that is selected.

 

Really scratching my head here!

Link to comment
Share on other sites

That's kind of where I am struggling. I thought that if I added it to the URL it would mean that when it was clicked (thus calling the data through the council-indiv.php page) it would show that button with the different css class (class="subthere"). However, I can see that I am wrong, as it simply colours all buttons with that class.

 

Any other ideas how to get a menu 'selected' button to work?

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.