php - 仅具有一个标题的按月输出

标签 php mysql grouping

我一直在尝试将其从当前输出转换为“按月”输出。我要把我所有的头发都拔出来。我想做的是以月为单位对游戏进行分组。因此,一月、二月、三月等都会在其下方包含每个游戏。现在,我必须为每个团队执行此操作,并为每个团队创建一个静态占位符和新变量。

数据库结构

[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";
}

?>

最佳答案

更改数据库结构中的日期格式,并包括开始日期和结束日期以根据这样的月份获取数据:这将为您提供月份数据,希望它有用

 $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++;
    }

关于php - 仅具有一个标题的按月输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779301/

相关文章:

php - 如何让 CKeditor 从 Hspace 和 Vspace 切换到正确的 CSS

php - 如何优化加载 API 的 php 脚本以加快加载速度

php - 使用php通过ssh备份mysql数据库

mySQL 将关系排序为下一个更高的数字

php - 如何使用 mysql 数据库中的数据创建 Google ComboChart?

MYSQL内连接有限制吗?

arrays - 将字符串数组拆分为字符串数组的数组

php - 如何通过 phplocalmyadmin 将 2+ MB 文件上传到 xampp MySQL?

excel - 使用分组变量计算值的 95%

cassandra - Spark Cassandra 连接器 keyBy 和 shuffle