What is the number of fields in a query array?

Source: Internet
Author: User
$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 Sex
Order number: ". $row [OrderID]." Status: ". $row [' Zhuangtai ']."
$v $shouji _arr[$k] $sex _arr[$k]
";


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.
}

  • 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.