有关问题未解决,接着提问!关于查询结果特殊显示的有关问题

WBOY
Release: 2016-06-13 10:07:51
Original
811 people have browsed it

问题未解决,接着提问!关于查询结果特殊显示的问题!
原帖:http://topic.csdn.net/u/20120214/16/171276bf-16a7-45a3-8224-fea338db7ee0.html?1686623126 

这个帖子不能再回复了,另开一贴:

数据库结构、字段如下图:


要想达到这样的显示效果:


论坛上 jordan102 朋友帮忙写了个查询过程,PHP文件代码如下:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpmysql_connect ('127.0.0.1','root','');mysql_select_db('jiagedata');$result=mysql_query("select year(add_date) as y,group_concat(yc_jiage) as str from yc_jiage group by year(add_date);") or die(mysql_error());      echo '<table>';while($row = mysql_fetch_assoc($result)){      echo '<tr>';      echo "<td>$row[y]</td>";      foreach(explode(',',$row['str']) as $v);            echo "<td>$v</td>";      echo "</tr><tr>";}      echo "";?><br><br>运行结果不是我想要的,而是下面的结果:<br><br><br>显然数据没有全部列出,请教大家,到底哪里出错!<br>jordan102 朋友,还在吗?<br><br><font color="#e78608">------解决方案--------------------</font><br>数据格式变一下。试试看行不行。<br>sql语句改为:  <br>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)<br><br><dl class="code">PHP code<pre class="brush:php;toolbar:false">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 $k1=>$n)           $tmp[$k][$n]=$s_arr[$k1]; } echo '
Copy after login
'; echo ""; echo ""; for($i=1;$i{$i}月"; echo ""; foreach($tmp as $k2=>$v){ echo ""; echo ''; for($i=1;$i$v[$i]"; } echo ''; } echo '
年\月
'.$k2.'
';
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!