Php 表中的下拉菜单显示两列,例如下拉列表中的subid-subcategory

Php 表中的下拉菜单显示两列,例如下拉列表中的subid-subcategory,php,dropdown,Php,Dropdown,嗨,我从一张有效的桌子上得到了这个下拉列表 $cat_id=$_GET['cat_id']; require "configure.php"; $q=mysql_query("select * from arbejdsopgave where cat_id='$cat_id' and status2!='lukket'"); echo mysql_error(); $myarray=array(); $str=""; while($nt=mysql_fetch_array($q)){ $s

嗨,我从一张有效的桌子上得到了这个下拉列表

   $cat_id=$_GET['cat_id'];
require "configure.php";
$q=mysql_query("select * from arbejdsopgave where cat_id='$cat_id' and status2!='lukket'");
echo mysql_error();
$myarray=array();
$str="";
while($nt=mysql_fetch_array($q)){
$str=$str . "\"$nt[subcategory]\"".",";
}
$str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string
echo "new Array($str)";
但是,我想在“sub_id”列的下拉列表中显示的字符串中添加一列,以便下拉列表显示 sub_id-子类别。例如:

673-新屋顶,而不是仅显示新屋顶的当前屋顶

我尝试组合一个字符串,如下所示,但结果是首先是子类别,然后是列表中的子ID,例如。 子目录1 副2 次级T3 1. 2. 三,


希望您能在正确的轨道上帮助我

如果您使用MYSQL作为后端,那么只需使用query来解析结果,如下所示

select CONCAT('sub_id ', 'subcategory') as category,othercolumnnames from arbejdsopgave where cat_id='$cat_id' 
and status2!='lukket';
select CONCAT('sub_id ', 'subcategory') as category,othercolumnnames from arbejdsopgave where cat_id='$cat_id' 
and status2!='lukket';