Hi I know this might sound familiar to other questions here in stackoverflow but what I'm trying to derived on this question, are there any possible way on how you can GROUP a list of MONTH and YEARS with its Days are listed too but are grouped in different months. Like what is shown below:
- January, 2016
- January 1, 2016
- January 2, 2016
- February, 2016
- February 1, 2016
- February 2, 2016
I actually have a form and what it does is you can search with a filter of DATE FROM and DATE TO and another filter of MONTHLY viewing. So let you selected the MONTHLY filter and a date range of January 01, 2016 to February 29, 2016 it should display like this.
FIRST GROUP:
- January, 2016
- January 1, 2016
- January 2, 2016
- etc.. to January, 31, 2016
SECOND GROUP:
- February, 2016
- February 1, 2016
- February 2, 2016
- etc.. to February, 29, 2016
My query is just simple:
$query = msyqli_query($con, "select YEAR(maxi_date),MONTH(maxi_date) from maxi_summaryreport where maxi_date between '2016-01-01' and '2016-02-29' group by YEAR(maxi_date), MONTH(maxi_date)");
$ahtquery = "select maxi_aht,maxi_callsanswered from maxi_summaryreport where maxi_date Between '2016-01-01' and '2016-02-29' and maxi_location='Zapote'
";
$ahtq = mysqli_query($con, $ahtquery);
while($ahtf1 = mysqli_fetch_assoc($ahtq))
{
$aht1 = $ahtf1['maxi_aht'];
$ahtout1[] = $aht1;
//echo $aht1."-summary report<br>";
$cal1 = $ahtf1['maxi_callsanswered'];
$calout1[] = $cal1;
//echo "<br>".$cal1." - ".$aht1."<br>";
}
while($row = mysqli_fetch_array($query))
{
echo "<br>".$calout1[$a]." - ".$ahtout1[$a]."<br>";
$a++;
}
But what it only display is:
FIRST GROUP
- 2016-01-01
SECOND GROUP
- 2016-02-01
not
FIRST GROUP
- 2016-01-01
- 2016-01-02
- 2016-01-03
- ...etc. to 2016-01-31
SECOND GROUP
- 2016-02-01
- 2016-02-02
- 2016-02-03
- ...etc to 2016-02-29
Can somebody help me I've really been looking over the net for some ideas to workaround but I'm not really good at sql. Thank you so much for any help.
Hi Guys thank you so much for all the help and ideas you've given me I just found the solution to my problem. Here's the code below.
$q=mysqli_query($con,"SELECT DISTINCT MONTH(maxi_date),YEAR(maxi_date), maxi_srid,maxi_date FROM maxi_summaryreport where maxi_location='Zapote' and
maxi_date between '$datefrom' and '$dateto' group BY MONTH(maxi_date), YEAR(maxi_date)");
foreach($q as $cat){
echo '<li id="'.$cat['MONTH(maxi_date)'].'" class="files">';
echo '<a href="'.$cat['maxi_srid'].'">'.$cat['MONTH(maxi_date)'].", ".$cat['YEAR(maxi_date)'].'</a>';
echo '<ul class="sub-menu">';
echo $cat['maxi_srid'];
$linkq=mysqli_query($con,"SELECT * FROM maxi_summaryreport WHERE maxi_location = 'Zapote' and MONTH(maxi_date)='" . $cat['MONTH(maxi_date)'] . "'");
foreach($linkq as $link){
echo '<li><a href="#">'.$link['maxi_date'].'</a></li>';
echo mysqli_num_rows($linkq);
}
echo '</ul></li>';
}