dongtangyi8962 2016-09-20 20:11
浏览 31

单个日期标题下的PHP回显结果

I have a large database that I am querying. There are multiple results that share the same "Date". SO, I might have 5 results today and 8 results yesterday and so on.

I echo the result so that each article has the "date" below the title right now. But, I am searching how to show the DATE HEADER and then the article headlines below each date that is grouped.

SO:

September 19, 2016

  • Article 1 Title
  • Article 2 Title
  • Article 3 Title
  • Article 4 Title

September 17, 2016

  • Article 1_1 Title
  • Article 2_1 Title
  • Article 3_1 Title

... so on.

Here is a snapshot of my MYSQL. Thanks super mucho in advanced NINJAS!!

enter image description here

Code is below:

<?php do { ?>

<b><?php echo date('M. j, Y', ($row_Recordset2['date'])); ?></b><br />
<b><a href="/full.php?id=<?php echo $row_Recordset2['id']; ?>"><?php echo stripslashes(htmlspecialchars($row_Recordset2['title'])); ?></a></b><br />
<?php echo (stripslashes(str_replace("{nl}", "<br />", $row_Recordset2['short']))); ?>


<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
  • 写回答

1条回答 默认 最新

  • duan1396 2016-09-20 20:34
    关注

    1) Do not use do..while, use only while 2)

    <?php $current_date = '';
        while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)){
          if($current_date !== $row_Recordset2['date']){
            echo '<b>' . date('M. j, Y', ($row_Recordset2['date'])) . '</b>';
            $current_date = $row_Recordset['date'];
        }
          echo "<b><a href=\"/full.php?id=$row_Recordset2[id]\">".     stripslashes(htmlspecialchars($row_Recordset2['title'])) . "</a></b><br />" .
          (stripslashes(str_replace("{nl}", "<br />", $row_Recordset2['short'])));
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)