在mysql表表数据中,一列有多个这样的值,
code name
1,2,3 a
4 b
我想要的输出是
code name
1 a
2 a
3 a
4 b
这是我的代码:
$sql="SELECT * FROM hsc_sub group by sub_name order by sub_code";
$res = app_db_query($app,$sql);
while($row = mysqli_fetch_assoc($res)){
//enter code here
$subj[] = $row;
$subj[] = explode(",",$row['sub_code']);
}
答案 0 :(得分:1)
在ForEach循环中,我们可以满足您的要求。
$subCode[];
$name[];
echo("Code");
echo("\t");
echo("Name");
echo("\n");
$sql="SELECT * FROM hsc_sub group by sub_name order by sub_code";
$res = app_db_query($app,$sql);
while($row = mysqli_fetch_assoc($res)){
$nm = $row['sub_name']
$sub[] = explode(",",$row['sub_code']);
foreach($sub as $item)
{
$name.push($nm);
$subCode.push($item);
echo($item);
echo("\t");
echo($nm);
echo("\n");
}
}