On Jun 23, 2003, "David Elìas Sánchez Vásquez" claimed that: | |Hi folks | |I'd like to know if you know any page where I can download a tree dynamic |menu made in PHP.. The options of this menu will be pulled from a mysql |database | |thanks | |David
I know this breaks the "rules/recommendations" that were just discussed on this list about whether a function should output, but tough. IRIC, this was lifted from somewhere on phpbuilder.com <?php function build_select_box($result, $name, $checked_val="*Choose an Option*") { /* Takes a $result set, with the first column being the "id" or value and the second column being the text you want displayed. The second parameter is the $name you want assigned to this form element The third parameter is optional. Pass the value of the item that should be selected by default. */ $rows=mysql_num_rows($result); print("<SELECT NAME=\"$name\">"); for ($i=0; $i<$rows; $i++) { print("\n<OPTION VALUE=\"".mysql_result($result,$i,0)."\""); if(mysql_result($result,$i,1) == addslashes($checked_val)) { print(" SELECTED style='background-color: #FFFFCE'"); } print(">".stripslashes(mysql_result($result,$i,1))); print("</OPTION>"); } // End for print("\n</SELECT>\n"); } // End function print("<HTML><BODY><FORM action=\"action.php\">"); $SQLQuery="SELECT col1, col2 FROM table ORDER BY col2"; $mysql_result=mysql_query($SQLQuery, $database_link); build_select_box($mysql_result,"selected_item"); print("</form></body></html>"); ?> -- Registered Linux user #304026. "lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import" Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED Responses to this message should conform to RFC 1855. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php