Query the number of touch fields in the array?
$ 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 |
Gender |
"; 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 a loop output column. I want to know how to get it.
$v$shouji_arr[$k]$sex_arr[$k]
Where is the number of $ v? After the actual output is displayedHow many rows are there? Because I need to add a merged cell, similarMerged cellsBecause I don't know this groupThe number of rows in the table, that is, the number of $ v. Therefore, we do not know the value of rowspan!
I don't know what I said, but you can't hear it clearly. this is the foreach output display, but you cannot determine the number of output rows. you need to get the number of $ v because one $ v occupies one 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 (*) in the SQL string to get
You can also define an integer variable 0 outside the foreach loop.
Auto-increment in the loop body
For example
$ I = 0;
Foreach ()
{
$ I ++;
}
This post was last edited by xuzuning at 15:55:30
Foreach ($ t = explode (',', $ row ['name']) as $ k => $ v ){
Count ($ t) is the number of $ v
You can also add a count (*) in the SQL string to get
Thank you very much for the answers from the moderator and @ zhangbin1988. if I add
12121
Even if the cells are merged, the merged cells will output count ($ t) times cyclically. how can this cell be output only once? If this cell is placed separately outside foreach, it is misplaced!
$ T = explode (',', $ row ['name']);
$ S ="Merged cell content";
Foreach ($ t as $ k => $ v ){
Echo"". $ S;
Echo"$ V$ Shouji_arr [$ k]$ Sex_arr [$ k]";
Echo"";
$ S = ''; // clear after the output
}