gpt4 book ai didi

php - 分组依据(备注)php mysql中的值

转载 作者:行者123 更新时间:2023-11-28 02:55:42 26 4
gpt4 key购买 nike

下面是产品表:

id | mid | wgh | remark| remkok | 
1 3 1.5 r3ok 1
2 2 1.5 0
3 2 0.6 nice 0
4 1 1.2 okh 0
5 4 1.5 bye 0
6 4 2.4 okby 0
7 3 3.0 oknice 1

我想在组的 tr 下方显示备注,如下所示

    mid   wgh  
3 1.5
3.0
remarks : r3ok, oknice
4 1.5
2.4
remarks : bye, okby
2 1.5
0.6
remarks : , nice
1 1.2
remarks : okh

我的尝试如下:

$pid= null;
while($row = mysql_fetch_array($result))
{

$rowpkts = $row['mid'];
echo "<tr class=\"undercl\">";
if($rowpkts != $pid){
echo'<td align="center" valign="top">'.$row["mid"].'</td>';
}else{
echo'<td align="center" valign="top"></td>';
}

echo'<td align="center" valign="top">'.$row["wgh"].'</td>';

echo "</tr>";

// what i tried to build for remarks as below

$remsql = "SELECT mid as onu , GROUP_CONCAT(`remark` ORDER BY `id` ASC SEPARATOR ', ') AS plrmks
FROM products WHERE 1=1 GROUP BY `mid`";
$fetchremk = mysql_query($remsql);
$rowresults = mysql_fetch_array($fetchremk);

if($rowresults['onu'] == $pid ){

echo"<tr style='border-style:underline;'>";
echo'<td align="center" align="top">'.$rowresults["plrmks"].'</td>';
echo"</tr>";
}
}
$pid = $rowpkts;
}

但是 tr 下方的 remarks 不正确...这意味着它不会显示在 mid=3 或 mid=1 以下。

任何其他方式,这对我有帮助。

最佳答案

根据需要添加适当的colspan,不要做居中对齐。

试试下面的代码

while($row = mysql_fetch_array($result))
{

$rowpkts = $row['mid'];
echo "<tr class=\"undercl\">";
if($rowpkts != $pid){
echo'<td align="center" valign="top">'.$row["mid"].'</td>';
}else{
echo'<td align="center" valign="top"></td>';
}
echo'<td align="center" valign="top">'.$row["wgh"].'</td>';

echo '</tr>';
$remsql = "SELECT mid as onu , GROUP_CONCAT(`remark` ORDER BY `id` ASC SEPARATOR ', ') AS plrmks
FROM products WHERE `remkok`= 1 GROUP BY `mid`";
$fetchremk = mysql_query($remsql);
$rowresults = mysql_fetch_array($fetchremk);

if($rowresults['onu'] == $pid ){

echo"<tr><td colspan ='?'> Remarks : ";
echo $rowresults["plrmks"];
echo "</td></tr>";
}
$pid = $rowpkts;
}

关于php - 分组依据(备注)php mysql中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37205131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com