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 "
| Year \ Month | "; for ($i =1; $i <=12; $i + +) echo "
{$i} month | "; echo "
"; foreach ($tmp as $k 2=> $v) { echo "
"; Echo '
| '. $k 2. ' | '; for ($i =1; $i <=12; $i + +) { echo "
$v [$i] | "; } Echo '
'; } Echo '
';