Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将MySQL查询结果按日期分组,每个组都有头和自己的div_Php_Html_Mysql_Sql - Fatal编程技术网

Php 将MySQL查询结果按日期分组,每个组都有头和自己的div

Php 将MySQL查询结果按日期分组,每个组都有头和自己的div,php,html,mysql,sql,Php,Html,Mysql,Sql,我觉得我可能想得太多了。。。所以我想我应该得到一些额外的建议。我想在我的数据库中查询单个标题下具有相同日期的“事件”和组事件的列表。此外,我想将此“组”放在它自己的容器中。我已经解决了浏览其他问题时的单标题问题,但是容器让我很伤心 例如: <div class='container'> <img src='event-image.jpg'> <h1>October 15th, 2012</h1> <h3>Even

我觉得我可能想得太多了。。。所以我想我应该得到一些额外的建议。我想在我的数据库中查询单个标题下具有相同日期的“事件”和组事件的列表。此外,我想将此“组”放在它自己的容器中。我已经解决了浏览其他问题时的单标题问题,但是容器让我很伤心

例如:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
这个:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
不是这个:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
MySQL查询:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
HTML/PHP:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>

">

结果:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
October 15, 2012
Event 1
Event 2
Event 3
October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3
$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;
<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>
<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>

2012年10月13日
Relient K w/Hellogoodby,William Beckett&英雄之家
凯恩舞厅|塔尔萨,好的| 9:00 | 10美元

Rod Steward&Stevie Nicks 博克中心|塔尔萨,OK | 9:00 | 45美元

加里·艾伦 硬岩赌场酒店|塔尔萨,OK | 9:00 | 30美元

2012年10月14日 Nalani Proctor和Kierston White 蓝邦|诺曼,好的| 9:00 | 5美元

平房 蓝邦|诺曼,好的| 9:00 |自由

Relient K w/Hellogoodby,William Beckett&英雄之家 凯恩舞厅|塔尔萨,好的| 9:00 | 10美元

我希望这不会太复杂!感谢您的帮助!谢谢!

试试这个:

$prevDate = null;
while ($row = $result->fetch_assoc()) {
    $mark = false;
    if ($row['postdate'] != $prevDate) {
        $mark = true;
        $prevDate = $row['postdate'];
    }
    ?>
    <? if ($mark) { ?>
        <div class="content">
        <? } ?>
        <? if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?= $row['image'] ?>">
        <? } ?>

        <? if ($mark) { ?>
            <h1><?= $row['postdate']; ?></h1>
        <? } ?>
        <h3><?= $row['title']; ?></h3>   
        <p><?= $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " . $row['cost']; ?></p>
        <? if ($mark) { ?>
        </div>
        <div class="horizontal-line"></div>
    <? } ?>
<? } ?>
$prevDate=null;
而($row=$result->fetch_assoc()){
$mark=false;
如果($row['postdate']!=$prevDate){
$mark=true;
$prevDate=$row['postdate'];
}
?>
">


多亏“khomyakoshka”带领我朝着正确的方向前进,我才得以成功

…现在我不是说这是最好的方法,但它是有效的

<?php   
$prevDate = null;
$i = 0;
    while ($row = $result->fetch_assoc()) {
        $mark = false;
        if ($row['postdate'] != $prevDate) {
            $mark = true;
            $prevDate = $row['postdate'];
        }

        if ($mark && $i == 0) {
?>
            <div class="content">
<?php
        } elseif ($mark) {
?>          
            <div class="clear"></div>
            </div>
            <div class="horizontal-line"></div>
            <div class="content">
<?php           
        }

        if (!empty($row['image'])) { 
?>
            <img src="/images/thumbs/<?= $row['image'] ?>">
<?php
        }

        if ($mark) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
<?php
        }
?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " . $row['cost']; ?></p>
<?php
                $i++;
                }
            ?>
            <div class="clear"></div>
            </div>

">


它做错了什么?是水平线吗?您的示例没有提到带有
class=“content”
的项目,因此我无法判断这是否正确。我认为我的示例是这样做的……但它做错了的是包装每个“事件”(H3标记和P标记)在后面是水平规则…我希望它用相同的日期包装所有的“事件”,然后用一条水平线来添加视觉分隔。这更接近了!…我想我现在可能能够解决它。请看一个例子。它满足了你的需要。我将接受你的答案,因为你已经回答了这个问题,我举个例子st需要对其进行一些修改以适合我的代码。再次感谢!我将更经常地使用此位置。欢迎使用Stackoverflow=)