Need help customizing my dropdown menus.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nicolaou
Forum Newbie
Posts: 2
Joined: Sat Oct 29, 2005 8:38 am

Need help customizing my dropdown menus.

Post by nicolaou »

First time poster and complete PHP newbie. I've trawled through the first 10 pages of search results but cannot find an answer so I hope I can have better luck here.

I'm developing a php classifieds site and want to make a simple change to my dropdown menus. Currently, the only difference in appearance between all the categories in a dropdown is that the sub-categories are indented.

I'd like to to make the Main categories display in bold.

This is the code which creates my dropdowns:

Code: Select all

<?
			//Create the drop down list of categories
			// start with an empty $right stack 
			$right = array(); 

			// now, retrieve all descendants of the $root node 
			$result = mysql_query( "SELECT catname, catid, total, lft, rgt FROM $cat_tbl ORDER BY lft ASC;");

			// display each row 
			while ( $row = mysql_fetch_array($result) )
			{ 
				// only check stack if there is one 
				if( count($right) > 0 )
				{ 
					// check if we should remove a node from the stack 
					while( count($right) > 0 && $right[count($right)-1] < $row['rgt'] )
					{ 
						array_pop($right); 
					} 
				}

				// display indented node title 
				print "<option value='" . $row['catid'] . "'";
				if ($row['catid'] == $catid) { echo " selected"; }
				print ">";
				echo str_repeat("&nbsp;",count($right)).$row['catname']. " (" . $row['total'] . ")"; 
				print("</option>");

				// add this node to the stack 
				$right[] = $row['rgt']; 
			}

		?>
Any suggestions?



Also, for newcomers to php like myself, may I recommend the 'teach yourself' book PHP with MySQL by nat macbride
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

how do you identify which are the main categories?

maybe have an array of the main categories and then use in_array to check if it exists in the array, if it does bold it.
nicolaou
Forum Newbie
Posts: 2
Joined: Sat Oct 29, 2005 8:38 am

Post by nicolaou »

anyone?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

nicolaou wrote:anyone?
As mickd asked - how do you identify the main categories?

Mac
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

What are these left and right fields in the database? Are these the fields you used to identify main and sub categories? If so and if you are not in a hurry to produce the application, redesign the database.
Post Reply