Query the number of touch fields in the array?

Source: Internet
Author: User
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"
  
  "; While ($ row = mysql_fetch_assoc ($ r) {$ shouji_arr = explode (',', $ row ['shouji ']); $ sex_arr = explode (', ', $ row ['sex']); echo" 
   "; Foreach (explode (',', $ row ['name']) as $ k => $ v) {echo" 
   
     "; Echo" 
    "; Echo" 
   ";}} Echo" 
  
Name Mobile phone Gender
Order Number: ". $ row [orderid]." status: ". $ row ['zhuangtai']."
$ V $ Shouji_arr [$ k] $ Sex_arr [$ k]
";


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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.