Questions are not resolved, then ask! Questions about special display of query results

Source: Internet
Author: User
The problem is not solved, then ask! Questions about the special display of query results!
Original posts: http://topic.csdn.net/u/20120214/16/171276bf-16a7-45a3-8224-fea338db7ee0.html?1686623126

This post can no longer reply, another to open a paste:

Database structure, fields such as:


To achieve such a display effect:


Forum jordan102 Friends Help write a query process, PHP file code is as follows:

PHP Code
  
   
  
   '; while ($row = Mysql_fetch_assoc ($result)) {      echo ';      echo "$row [y]";      foreach (Explode (', ', $row [' str ']) as $v);            echo "$v";      echo "";}      echo "";? >


The result is not what I want, but the following result:


Obviously the data is not all listed, ask everyone, exactly where the error!
jordan102 friend, are you still there?

------Solution--------------------
The data format changes a bit. Try it, OK.
Change the SQL statement to:
Select year (add_date) as Y,group_concat (Yc_jiage) as Str,group_concat (Day (add_date)) as SS from Yc_jiage Group by year (add _date)

PHP Code
while ($row =mysql_fetch_assoc ($result)) {       $arr [$row [y]]= $row;}  foreach ($arr as $k = + $v) {      $s _arr=explode (', ', $v [str]), $n _arr=explode (', ', $v [SS]);      foreach ($n _arr as $k 1=> $n)           $tmp [$k] [$n]= $s _arr[$k 1];} Echo '
  
   
   
    
    
   '; echo "
   
    
    
       "; echo " 
      "; for ($i =1; $i <=12; $i + +) echo " 
      "; echo " 
     "; foreach ($tmp as $k 2=> $v) { echo " 
     
       "; Echo ' 
      '; for ($i =1; $i <=12; $i + +) { echo " 
      "; } Echo ' 
     '; } Echo ' 
    
Year \ Month{$i} month
'. $k 2. '$v [$i]
';
  • 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.