Heim  >  Artikel  >  Backend-Entwicklung  >  有关问题未解决,接着提问!关于查询结果特殊显示的有关问题

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

WBOY
WBOYOriginal
2016-06-13 13:44:26822Durchsuche

问题未解决,接着提问!关于查询结果特殊显示的问题!
原帖: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/

--><?php mysql_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 '
'; echo ""; echo ""; for($i=1;$i{$i}月"; echo ""; foreach($tmp as $k2=>$v){ echo ""; echo ''; for($i=1;$i$v[$i]"; } echo ''; } echo '
年\月
'.$k2.'
';
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn