[英]combobox treeview in php & mysql
Does anyone know how to display MySQL db hierarchical data (Nested Set Model ( http://www.phpro.org/tutorials/Managing-Hierarchical-Data-with-PHP-and-MySQL.html )) in a combo box as shown here under the "Category:" comboxbox field: http://dir.globetourism.biz/submit.php 有谁知道如何在组合框中显示MySQL db分层数据(嵌套集模型( http://www.phpro.org/tutorials/Managing-Hierarchical-Data-with-PHP-and-MySQL.html )),如下所示在“类别:” comboxbox字段下: http ://dir.globetourism.biz/submit.php
Thanks 谢谢
您需要做的是在打印组合框的<option>
标记时,您必须检查每个元素的depth
(如何获得深度在问题所链接的文章中),并打印出许多“ |”字符串和另外两个下划线(__)使其看起来很像树。
<?PHP
function GetCats($id='0',$sublev='0',$vname='C_Parent')
{
$DQ = new MySQLTable;
$DQ -> TblName = 'cat_categories';
$WHERE[$vname]['=']=$id;
$res = $DQ -> Select('C_ID,C_Name',$WHERE,'C_ID');
if (mysql_num_rows($res)>0)
{
while($row = mysql_fetch_assoc($res))
{
$ss='';
if($sublev!=='0')
{
for($i=0;$i<=$sublev*10;$i++)
{
$ss.=' ';
}
$ss.='|';
for($i=0;$i<=$sublev;$i++)
{
$ss.='-';
}
$ss.='>>';
}
$sel_s = '';
if(IsSet($_POST['C_Parent']))
{
if($row['C_ID']==$_POST['C_Parent'])
{
$sel_s = ' selected';
}
} elseif (IsSet($_POST['I_Parent'])) {
if($row['C_ID']==$_POST['I_Parent'])
{
$sel_s = ' selected';
}
} else {
$sel_s = '';
}
Echo "<option value=\"".$row['C_ID']."\" ".$sel_s.">".$ss.$row['C_Name']."</option>\r\n";
GetCats($row['C_ID'],$sublev+1);
}
}
}
Echo "<select name=\"C_Parent\">\r\n";
Echo "<option value=\"0\">...</option>\r\n";
GetCats();
Echo "</select>";
?>
Something like this. 这样的事情。
But here was my own MySQL class. 但是这是我自己的MySQL类。 The query is: SELECT C_ID,C_Name WHERE C_Parent=$id ORDER BY C_ID
where $id - php variable (current parent cat). 查询是: SELECT C_ID,C_Name WHERE C_Parent=$id ORDER BY C_ID
其中,$ id-php变量(当前的父目录cat)。
And there are $_POST variables if error submit to store selected. 并且有$ _POST变量,如果错误提交到存储选择。
This is not the most effective way to di it bcoz many queries. 这不是解决许多查询的最有效方法。 More effectively is to get all data to array to work with. 更有效的是使所有数据都可以与数组一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.