Php 按月输出,只有一个标题

Php 按月输出,只有一个标题,php,mysql,grouping,Php,Mysql,Grouping,我一直在尝试将其从当前输出转换为“按月”输出。我要把我所有的头发都拔出来。我想在几个月内把比赛分组。因此,1月、2月、3月ect会将每场比赛都放在下面。现在,我必须为每个团队都这样做,并为每个团队创建一个静态的占位符和新变量 数据库结构 [id] [opponent] [month] [team] [notes] [date_added] [buyLink] [time] [date] <?php // Check to see the URL variabl

我一直在尝试将其从当前输出转换为“按月”输出。我要把我所有的头发都拔出来。我想在几个月内把比赛分组。因此,
1月、2月、3月
ect会将每场比赛都放在下面。现在,我必须为每个团队都这样做,并为每个团队创建一个静态的
占位符和新变量

数据库结构

[id]   [opponent]   [month]   [team]   [notes]   [date_added]   [buyLink]
[time]   [date]

<?php
// Check to see the URL variable is set and that it exists in the database
// Connect to the `MySQL` database
include "../../includes/db_conx.php"; 
//--------------------------------------------------------------------------------------
$sqlcountRam = "SELECT * FROM discounts WHERE team='cyoram' ORDER BY date ASC";
$sql_countRam = mysqli_query($db_conx,$sqlcountRam);
$calCountRam = mysqli_num_rows($sql_countRam); 
//--------------------------------------------------------------------------------------
if ($calCountRam > 0) {
// get all the product details

 $x=0;
while($row = mysqli_fetch_assoc($sql_countRam)){


             $id = $row["id"];
             $opponent = $row["opponent"];
             $team = $row["team"];
             $notes = $row["notes"]; 
             $month = $row["month"];

             $buyLink = $row["buyLink"];

             $time = $row["time"];
             $date = $row["date"];
             $formatted_date = date("l d F Y H:i A", strtotime($date));
             $raw = "$formatted_date";
             $xplod = explode(' ',$raw);
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
include "includes/logos.php"; 


/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
 $classCssRam = "inline-block";
  $x++; 
$classChangeRam = ($x%2 == 0)? 'whiteBackground': 'grayBackground';

 $product_listRam .= "  
   <div class='aNew' style='clear:both;display:<?php echo $classCssRam; ?>'>

<div class='monthSalute'>$month</div>

    <table width='400px' border='0'>
                <tr class='$classChange'>
                    <td rowspan='2' class='date' >$xplod[1]</td>
                    <td class='day'>$xplod[0]</td>
                 <td rowspan='2' class='centerLogo'><div class='containImgPos'><img src='$imgLogo' height='32px' style='position:relative;left:$posImgR;' /></div></td>
                    <td class='city'>$city</td>
                    <td rowspan='2' class='butt_pad'><a href='calendar_edit.php?pid=$id'>edit</a> &bull; <a href='calendar_list.php?deleteid=$id'>delete</a></td>
                </tr>
                <tr class='$classChangeRam'>
                    <td class='time $classChangeRam'>$time</td>
                    <td class='opponent $classChangeRam'>$opponent</td>
              </tr>
    </table>
</div>



";
    }
    }
 else {
    $product_listRam = "";
    $classCssRam = "none";
}

?>
[id][counter][month][team][notes][date\u added][buyLink]
[时间][日期]

请参阅下面代码中使用的
$monthDiv

我还修复了一个错误。不能在字符串中使用
,只需插入变量即可

<?php
while($row = mysqli_fetch_assoc($sql_countRam)){


    $id = $row["id"];
    $opponent = $row["opponent"];
    $team = $row["team"];
    $notes = $row["notes"]; 
    $month = $row["month"];

    $buyLink = $row["buyLink"];

    $time = $row["time"];
    $date = $row["date"];
    $formatted_date = date("l d F Y H:i A", strtotime($date));
    $raw = "$formatted_date";
    $xplod = explode(' ',$raw);
    /* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ */
    include "includes/logos.php"; 

    /* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ */
    $classCssRam = "inline-block";
    $x++; 
    $classChangeRam = ($x%2 == 0)? 'whiteBackground': 'grayBackground';

    /* Print month heading for new month */
    if ($last_month != $month) {
        $monthDiv = "<div class='monthSalute'>$month</div>";
        $last_month = $month;
    } else {
        $monthDiv = "";
    }

    $product_listRam .= "  
   <div class='aNew' style='clear:both;display:$classCssRam;'>

   $monthDiv

    <table width='400px' border='0'>
                <tr class='$classChange'>
                    <td rowspan='2' class='date' >$xplod[1]</td>
                    <td class='day'>$xplod[0]</td>
                 <td rowspan='2' class='centerLogo'><div class='containImgPos'><img src='$imgLogo' height='32px' style='position:relative;left:$posImgR;' /></div></td>
                    <td class='city'>$city</td>
                    <td rowspan='2' class='butt_pad'><a href='calendar_edit.php?pid=$id'>edit</a> &bull; <a href='calendar_list.php?deleteid=$id'>delete</a></td>
                </tr>
                <tr class='$classChangeRam'>
                    <td class='time $classChangeRam'>$time</td>
                    <td class='opponent $classChangeRam'>$opponent</td>
              </tr>
    </table>
    </div>
";
}

对数据库结构中的日期格式进行更改,并包括开始日期和结束日期,以便根据月份获取数据,如下所示:这将为您提供月份数据,希望其有用

 $mon = 1;
 $i=1;
                    $specify = array();
                    while($mon <=12)
                    {
                        $startdate = '2012-'.$mon.'-01';
                        $enddate = '2012-'.$mon.'-31';`
    $result = mysql_query("SELECT * FROM discounts   WHERE `date` BETWEEN '".$startdate."' AND '".$enddate ."'");
$row[i] = mysql_fetch_assoc($result);
$i++;
    }
$mon=1;
$i=1;
$specify=array();

虽然($mon请提供包含少量数据的DB架构…Date是实际日期。很抱歉,我忘了添加那个Sudheesh。我在原始帖子中包含了它。对于每一行,检查
$month
是否与前一行相同。当月份发生变化时,只输出
monthSalute
DIV。为什么同时有
month
Date列?难道你不能从日期开始获取月份吗?@Barmar这是我在显示月份之前使用的方法。这可以忽略。感谢观察。谢谢。我一直在尝试调试它,而不必再次发布,但我似乎无法获取它。现在,看起来这个月的最后几天都被抛出了n大约。例如,我有12月份和一个游戏列表,然后是1月份和一个游戏列表。但是,由于某种原因,1月份的最后一场游戏有它自己的标题。你知道为什么会发生这种情况吗。我检查了数据库中的条目,它有正确的月份。例如,我有:[[一月--标题]]1月03日1月24日1月25日[[一月--标题]]1月26日1月29日