日期:2014-05-17  浏览次数:20440 次

查询数组中摸个字段的个数?
$r=mysql_query('select orderid,zhuangtai,group_concat(`name`) as name,group_concat(`shouji`) as shouji,group_concat(`sex`) as sex from `order` group by orderid');
 echo "<table width=950 border='1px solid'>";
 echo "<tr><th>姓名</th><th>手机</th><th>性别</th></tr>";
while($row=mysql_fetch_assoc($r)){
    $shouji_arr=explode(',',$row['shouji']);
    $sex_arr=explode(',',$row['sex']);
    echo "<td colspan=3>订单号:".$row[orderid]."&nbsp;&nbsp;状态:".$row['zhuangtai']."</td>";
    foreach(explode(',',$row['name']) as $k=>$v){
         echo "<tr>";
         echo "<td>$v</td><td>$shouji_arr[$k]</td><td>$sex_arr[$k]</td>";
         echo "</tr>";
    }
}
echo "</table>";


这是一个循环输出的列子,我想知道,怎么得到
<td>$v</td><td>$shouji_arr[$k]</td><td>$sex_arr[$k]</td>
中,$v的个数呢? 意思就是,怎么得到实际输出显示之后,这个<td>有多少行呢?因为我需要增加一个合并的单元格,类似与  <td rowspan="3">合并的单元格</td>  因为不知道这组<tr>中有多少行,也就是$v的个数,所以不知道rowspan 这个值是多少!


不知道我的表述,大家听没听清楚,就是 这个foreach 输出显示,但是不能确定输出多少行,需要得到$v的个数,因为一个$v占一行!
mysql php table border

------解决方案--------------------
$t = explode(',',$row['name']);
$s = "<td rowspan='".count($t)."'>合并的单元格的内容</td>";
foreach($t as $k=>$v){
  echo "<tr>" . $s;
  echo "<td>$v</td><td>$shouji_arr[$k]</td><td>$sex_arr[$k]</td>";
  echo "</tr>";
  $s = ''; //输出过了就清空
}