0

こんにちは、機能するテーブルからこのドロップダウンを取得しました。

   $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 - subcategory が表示されるようにしたいと思います。例えば:

673 - 新しい屋根のみを示す現在の代わりに新しい屋根。

以下のように文字列を組み合わせてみましたが、結果は最初にサブカテゴリになり、次にリスト内のサブ ID が続きました。例: subcat1 subcat2 subcat3 1 2 3

$cat_id=$_GET['cat_id'];
require "config.php";
$q=mysql_query("select * from arbejdsopgave where cat_id='$cat_id' and status2!='lukket'");
echo mysql_error();
$myarray=array();
$str="";
$subid="";
while($nt=mysql_fetch_array($q)){
$str=$str . "\"$nt[subcategory]\"".",";
$subid=$subid . "\"$nt[sub_id]\"".",";
$str2=$str." ".$subid;
}
$str2=substr($str2,0,(strLen($str2)-1)); // Removing the last char , from the string
echo "new Array($str2)";

正しい道で私を助けてくれることを願っています

4

1 に答える 1

0

MYSQL をバックエンドとして使用している場合は、以下のようにクエリを使用して結果を連結します。

select CONCAT('sub_id ', 'subcategory') as category,othercolumnnames from arbejdsopgave where cat_id='$cat_id' 
and status2!='lukket';
于 2015-10-21T15:14:54.250 に答える