Page 1 of 1

Need help customizing my dropdown menus.

Posted: Sat Oct 29, 2005 8:55 am
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

Posted: Sat Oct 29, 2005 9:08 am
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.

Posted: Tue Jan 17, 2006 9:50 am
by nicolaou
anyone?

Posted: Tue Jan 17, 2006 11:04 am
by twigletmac
nicolaou wrote:anyone?
As mickd asked - how do you identify the main categories?

Mac

Posted: Tue Jan 17, 2006 6:33 pm
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.