PHP选项选择菜单生成器函数-下拉菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP选项选择菜单生成器函数-下拉菜单相关的知识,希望对你有一定的参考价值。
I wrote this little bit of code myself so if you see where you can improve on it, let me know. This is great for making complex menu's and also for making sure your POST data gets saved and reselected when the screen refreshes. I use it in all my programs now, makes menu generation a snap.In order to use this you need to make sure you set at minimum
$menu_vars as an array of values and $menu_postvalue as a string to the be the name of the POST field. By default, if no $menu_values is set, $menu_vars will be set both to be the display and value.
Example Usage in the Snippet
I look forward to your feedback.
function menu_generator($menu_vars="",$menu_postvalue="",$menu_values="", $blank=true, $selected="", $class="") { if($selected) { $selector=$selected; } else { $selector=$_POST[$menu_postvalue]; } if(!$menu_values) { $menu_values=$menu_vars; } else { $menu_values=$menu_values; } echo "<select name="$menu_postvalue" $class >"; if($blank) { echo "<option value=""></option>"; } { $value=$menu_generate[$i]; $value2=$menu_generate2[$i]; if($value2 == $selector) { echo "<option value="$value2" selected="selected">$value</option>"; } else { echo "<OPTION value="$value2">$value</option>"; } } echo "</select>"; } $menu_postvalue = "Numbers"; menu_generator($menu_vars, $menu_postvalue);
以上是关于PHP选项选择菜单生成器函数-下拉菜单的主要内容,如果未能解决你的问题,请参考以下文章
获取 JavaScript 以识别在 HTML 下拉菜单中选择了哪个选项并返回运行 SQL 查询的 PHP 函数