$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 "
"; echo "
name |
Mobile phone |
Sex |
while ($row =mysql_fetch_assoc ($r)) { $shouji _arr=explode (', ', $row [' Shouji ']); $sex _arr=explode (', ', $row [' sex ']); echo "
Order number: ". $row [OrderID]." Status: ". $row [' Zhuangtai ']." | "; foreach (Explode (', ', $row [' name ']) as $k = + $v) { echo]
"; echo "
$v |
$shouji _arr[$k] |
$sex _arr[$k] | "; echo "
"; }} echo "
";
This is an iteration of the loop output, and I want to know how to get
$v $shouji_arr[$k] $sex _arr[$k]
, what is the number of $v? That means, how to get the actual output to show after thisHow many lines are there? Because I need to add a merged cell, similar to theMerged cellsBecause I don't know this groupHow many lines, that is, the number of $v, so do not know rowspan This value is how much!
Do not know my statement, we do not hear clearly, is this foreach output display, but can not determine how many lines of output, need to get the number of $v, because a $v to occupy a row!
Reply to discussion (solution)
foreach ($t =explode (', ', $row [' name ']) as $k = = $v) {
Count ($t) is the number of $v
You can also add a count (*) to the SQL string to get
You can also define an shaping variable outside the Foreach loop to be 0
Self-increment in the loop body
For example
$i = 0;
foreach ()
{
$i + +;
}
This post was last edited by xuzuning on 2013-03-16 15:55:30
foreach ($t =explode (', ', $row [' name ']) as $k = = $v) {
Count ($t) is the number of $v
You can also add a count (*) to the SQL string to get
Thank you very much for the moderator's answer, and @zhangbin1988 's answer, if I add a direct in the foreach
12121
, the merged cell will also loop through the count ($t) times, so how can I output this cell only once? If this cell is placed alone in the outside of the foreach, it is misplaced, ask the big guys!
$t = Explode (', ', $row [' name ']);
$s = "contents of merged cells";
foreach ($t as $k = = $v) {
echo "". $s;
echo "$v $shouji_arr[$k] $sex _arr[$k]";
echo "";
$s = "; Empty when the output is over.
}