首先,如果您需要根据选择将用户发送到不同的页面,您应该创建一个字段“destination”,您可以在其中将 url 保存在数据库中:
CREATE TABLE `type` (
`id_type` int(4) unsigned NOT NULL auto_increment,
`id_cat` int(4) unsigned NOT NULL,
`name` varchar(40) NOT NULL,
`destination` varchar(40) NOT NULL,
PRIMARY KEY (`id_type`)
) ENGINE=MyISAM AUTO_INCREMENT=15 ;
然后从表中获取 url 并将它们放在选项值上
public function ShowCategory()
{
$sql = "SELECT * FROM category";
$res = mysql_query($sql,$this->conn);
$category = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$category .= '<option value="' . $row['destination'] . '">' . $row['name'] . '</option>';
}
return $category;
}
最后制作一个 jQuery 以重定向到提交页面
$("#select_form").submit(function( event ) {
var the_url = $("#type").val();
window.location = the_url;
event.preventDefault();
});
希望有所帮助。