Home  >  Article  >  Backend Development  >  查询数组中摸个字段的个数?解决思路

查询数组中摸个字段的个数?解决思路

WBOY
WBOYOriginal
2016-06-13 12:50:11753browse

查询数组中摸个字段的个数?

$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');<br />
 echo "<table width=950 border='1px solid'>";<br />
 echo "<tr><th>姓名</th><th>手机</th><th>性别</th></tr>";<br />
while($row=mysql_fetch_assoc($r)){<br />
    $shouji_arr=explode(',',$row['shouji']);<br />
    $sex_arr=explode(',',$row['sex']);<br />
    echo "<td colspan=3>订单号:".$row[orderid]."  状态:".$row['zhuangtai']."</td>";<br />
    foreach(explode(',',$row['name']) as $k=>$v){<br />
         echo "<tr>";<br />
         echo "<td>$v</td><td>$shouji_arr[$k]</td><td>$sex_arr[$k]</td>";<br />
         echo "</tr>";<br />
    }<br />
}<br />
echo "</table>";


这是一个循环输出的列子,我想知道,怎么得到
<td>$v</td><td>$shouji_arr[$k]</td><td>$sex_arr[$k]</td>
中,$v的个数呢? 意思就是,怎么得到实际输出显示之后,这个

有多少行呢?因为我需要增加一个合并的单元格,类似与   合并的单元格  因为不知道这组中有多少行,也就是$v的个数,所以不知道rowspan 这个值是多少!


不知道我的表述,大家听没听清楚,就是 这个foreach 输出显示,但是不能确定输出多少行,需要得到$v的个数,因为一个$v占一行!
mysql php table border
------解决方案--------------------
$t = explode(',',$row['name']);
$s = "合并的单元格的内容";
foreach($t as $k=>$v){
  echo "" . $s;
  echo "$v $shouji_arr[$k] $sex_arr[$k]";
  echo "";
  $s = ''; //输出过了就清空
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn