Hi I have data in my MYSQL which I am trying to sort by Months and Year together and display it in new HTML table every time sort by Year and months.
trying to do like this -
January 2021
Reise Nr. Reisedatum Dauer Flug Reis
2122330 Di, 1. jan – Do, 24. jan 2022 23 T AF Mali Intensiv
February 2021
Reise Nr. Reisedatum Dauer Flug Reis
2122330 Di, 1. Feb – Do, 24. Feb 2022 23 T AF Mali Intensiv
(Months wise data)
But HTML table is sorted by year only not months. see below the output.
But I am trying to make it like this January 2021 data is different table and OKT = October 2021 data in new table like below image
Here is my PHP CODE -
<?php
$tabelle="Termine_afrika";
$keysuffix="";
$status = array('freie Plätze','ausgebucht','nicht mehr buchbar','Restplätze','auf Anfrage','entfällt');
function starttable($year,$month)
{
?>
<table class="termine" >
<caption><?php echo date("F",strtotime($month)); ?> <?php echo $year ?></caption>
<thead>
<tr>
<th scope="col" class="reisenr">Reise Nr.</th>
<th scope="col" class="datum">Reisedatum</th>
<th scope="col" class="dauer">Dauer</th>
<th scope="col" class="flug">Flug</th>
<th scope="col" class="reise">Reise</th>
<th scope="col" class="preis">Reisepreis</th>
<th scope="col" class="status">Status</th>
</tr>
</thead>
<tbody>
<?
}
function closetable()
{
echo "
</tbody>
</table>
";
}
function ausgabe_einfach($zeile)
{
global $status;
$anfang = htmlentities($zeile->beginn_f,ENT_COMPAT,'UTF-8',0);
$ende = htmlentities($zeile->ende_f ,ENT_COMPAT,'UTF-8',0);
$commen = ($zeile->comment_de) ? "<div class=\"comment\">". nl2br(htmlentities($zeile->comment_de,ENT_COMPAT,'UTF-8',0)) ."</div>" : "";
?>
<tr>
<td><?php echo $zeile->reisenr ?></td>
<td><?php echo $anfang ?> – <?php echo $ende . $commen ?></td>
<td><?php echo $zeile->tage ?> T</td>
<td><?php echo $zeile->airline ?></td>
<td><?php echo $zeile->tourname ?></td>
<td><?php echo ($zeile->price) ? $zeile->price." Euro" : "-" ?> </td>
<td><?php echo $status[$zeile->status] ?></td>
</tr>
<?
}
$connection = #mysqli_connect("localhost","user","pass","DB");
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
if ($connection)
{
mysqli_set_charset($connection, "UTF8");
mysqli_query($connection, "SET lc_time_names = 'de_DE'");
$keywords = "mali";
$zeig = 1;
if ($keysuffix == "")
$where = "WHERE keycountry LIKE \"".$keywords."\" AND zeig='$zeig'" ;
else
$where = "WHERE ( keycountry LIKE \"".$keywords."\" OR keycountry LIKE \"".$keywords.$keysuffix."\" )";
$abfrage = "SELECT reisenr,beginn,ende,airline,status,price,keywords,keycountry,tourname, YEAR(beginn) AS jahr, DATE_FORMAT(beginn,\"%a, %e. %b\") AS beginn_f,DATE_FORMAT(ende,\"%a, %e. %b %Y\") AS ende_f,comment_de, DATEDIFF(ende,beginn) as tage FROM $tabelle $where ORDER BY jahr, beginn";
$ergebnis = mysqli_query($connection, $abfrage);
$opentab = false; // Tabelle offen
$count=0; // Aktueller Jahresdurchlauf
while($row = mysqli_fetch_object($ergebnis))
{
if (intval($row->jahr) > $count)
{
$count=$row->jahr;
$bigin = $row->beginn;
if ($opentab)
closetable();
starttable($count,$bigin);
$opentab = true;
}
ausgabe_einfach($row);
}
if ($opentab)
closetable();
}
else
{ ?>
Daten können nicht geladen werden.
<?
}
?>
do comparison between months not years and get month from DB also break line and add new line only when month change
Update query
$abfrage = "SELECT reisenr,beginn,ende,airline,status,price,keywords,keycountry,tourname, YEAR(beginn) AS jahr, MONTH(beginn) AS month, DATE_FORMAT(beginn,\"%a, %e. %b\") AS beginn_f,DATE_FORMAT(ende,\"%a, %e. %b %Y\") AS ende_f,comment_de, DATEDIFF(ende,beginn) as tage FROM $tabelle $where ORDER BY jahr, MONTH(beginn)";
update code
$p_month=0;
// Aktueller Jahresdurchlauf
while($row = mysqli_fetch_object($ergebnis))
{
if ($row->month != $p_month)
{
$p_month=$row->month;
$count=$row->jahr;
$bigin = $row->beginn;
if ($opentab)
closetable();
starttable($count,$bigin);
$opentab = true;
}
ausgabe_einfach($row);
}
Related
I am trying to group my data with country and year together and display it in a table but it is currently only grouped by year and not country.
As below -
USA 2020
| Reise | Land | Reisedatnum | Dauer | Reise |
| ------- | ------ | ------------- | ------- | ------- |
|12324 | Ak | 23-10-22 | AF |intensive|
USA 2020
|Reise |Land |Reisedatnum |Dauer |Reise|
|-|-|-|-|-|
|12323 |AG |3-10-22 |AF| intensive|
But it should be shown in one table only as Country and year are the same, currently is showing in a different table. I also grouped by keyregion
In database
keyregion = countryname
Year = $count=$row->jahr;
MySQL Query
function starttable($year,$country)
{
;
?>
<table class="termine" >
<caption class="date"><b><?php echo $country;?> <?php echo $year; ?> </b></caption>
<thead>
<tr>
<th scope="col" class="reisenr">Reise Nr.</th>
<th scope="col" class="land">Land</th>
<th scope="col" class="datum">Reisedatum</th>
<th scope="col" class="dauer">Dauer</th>
<th scope="col" class="reise">Reise</th>
<th scope="col" class="preis">Reisepreis</th>
</tr>
</thead>
<tbody>
<?
}
function closetable()
{
echo "
</tbody>
</table>
";
}
function ausgabe_einfach($zeile)
{
global $status;
$anfang = htmlentities($zeile->beginn_f,ENT_COMPAT,'UTF-8',0);
$ende = htmlentities($zeile->ende_f ,ENT_COMPAT,'UTF-8',0);
$commen = ($zeile->comment_de) ? "<div class=\"comment\">". nl2br(htmlentities($zeile->comment_de,ENT_COMPAT,'UTF-8',0)) ."</div>" : "";
?>
<tr>
<td><?php echo $zeile->reisenr ?></td>
<td><?php echo $zeile->keycountry .''.'<br>' . $zeile->Shortlink . ''?></td>
<td class="commdate"><?php echo $anfang ?> – <?php echo $ende ?></td>
<td><?php echo $zeile->tage+1 ?> T</td>
<td><?php echo $zeile->tourname ?></td>
<td><?php echo ($zeile->price) ? $zeile->price." Euro" : "-" ?> </td>
</tr>
<?
}
// Datenbankverbindung
$connection = #mysqli_connect("localhost","username","password","DB");
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
if ($connection)
{
mysqli_set_charset($connection, "UTF8");
mysqli_query($connection, "SET lc_time_names = 'de_DE'");
$keywords = "Afrika";
$zeig = 1;
if ($keysuffix == "")
$where = "WHERE keyregion LIKE \"".$keywords."\" AND zeig='$zeig'" ;
else
$where = "WHERE ( keyregion LIKE \"".$keywords."\" OR keycountry LIKE \"".$keywords.$keysuffix."\" )";
$abfrage = "SELECT reisenr,beginn,ende,airline,status,price,keywords,keyregion,Shortlink,keycountry,tourname, YEAR(beginn) AS jahr, MONTH(beginn) AS month, DATE_FORMAT(beginn,\"%a, %e. %b\") AS beginn_f,DATE_FORMAT(ende,\"%a, %e. %b %Y\") AS ende_f,comment_de, DATEDIFF(ende,beginn) as tage FROM $tabelle $where ORDER BY jahr, keyregion";
$ergebnis = mysqli_query($connection, $abfrage);
$opentab = false; // Tabelle offen
$p_month=0;
// Aktueller Jahresdurchlauf
while($row = mysqli_fetch_object($ergebnis))
{
if ($row->month != $p_month)
{
$p_month=$row->month;
$datee= htmlentities($row->beginn,ENT_COMPAT,'UTF-8',0);
$count=$row->jahr;
$country= $row->keyregion;
$bigin =htmlentities($row->beginn,ENT_COMPAT,'UTF-8',0);
if ($opentab)
closetable();
starttable($count,$country);
$opentab = true;
}
ausgabe_einfach($row);
}
if ($opentab)
closetable();
}
else
{ ?>
Daten können nicht geladen werden.
<?
}
I want to display results from 4 querys into one single html-table (SQL Server 2012, PHP, HTML). I already can display the results from one database-table, but as soon as I start to query the other 3 tables it only returns one row from the first table.
The following code only has one query and works fine - it displays several information about patients (Name, Station, Room, Catheter, Personal-ID, Date of Catheter-Insertion..), at the moment there are three different patients at the table, therefore the html-table shows 3 rows:
<?php
require_once('header.php');
$today = date("d.m.y");
$yesterday = date("d.m.y", time() - 60 * 60 * 24);
$dbyesterday = date("d.m.y", time() - 2*(60 * 60 * 24));
?>
<div class="container" style="padding-top: 80px">
<div id="table_admin" class="span7">
<h3 id="name" style="color: orange">Visitenliste</h3>
</br>
<table class="table table-responsive table-hover">
<thead>
<tr>
<th id="tc">Station</th>
<th id="tc">Patientennummer</th>
<th id="tc">Zimmer</th>
<th id="tc">Name</th>
<th id="tc">Katheterart</th>
<th id="tc">Anlagedatum</th>
<th id="tc"><?php echo $dbyesterday; ?></th>
<th id="tc"><?php echo $yesterday; ?></th>
<th id="tc"><?php echo $today; ?></th>
</tr>
</thead>
<?php
require_once('server.php');
// DB-Query für die Visitenliste
$sql = "SELECT dbo.patients.Patientennummer, Vorname, Nachname, Station, Zimmer, Katheterart, Anlagedatum, VisTod FROM dbo.patients INNER JOIN dbo.cathinsert ON dbo.patients.Patientennummer = dbo.cathinsert.Patientennummer ORDER BY Station ASC, Zimmer ASC";
$result = sqlsrv_query($connection, $sql);
if($result === false) {
die( print_r( sqlsrv_errors(), true) );
}
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
echo ("<tr class=\"clickable-row\" data-href=\"visitact.php?Patientennummer=".$row["Patientennummer"]."\">");
echo ("<td>".$row["Station"]."</td>");
echo ("<td>".$row["Patientennummer"]."</td>");
echo ("<td>".$row["Zimmer"]."</td>");
echo ("<td>".$row["Vorname"]." ".$row["Nachname"]."</td>");
echo ("<td>".$row["Katheterart"]."</td>");
echo ("<td>".$row["Anlagedatum"]."</td>");
echo ("<td>".$row["VisTod"]."</td></tr>");
}
?>
</table>
</div>
</div>
</body>
</html>
As a result, I have a table with 3 rows and all information I needed.
But as soon as I start adding more querys now, the additional information is displayed right, but only for the first row! Its the only row displayed at all. I really can't figure out, why this happens.
This is the code not working (all information is displayed right, even the information from the additional querys, but only one row --> only the first patient, although 3 are saved at the database and although the first code displays all 3 patients in the right way):
<?php
require_once('header.php');
$today = date("d.m.y");
$yesterday = date("d.m.y", time() - 60 * 60 * 24);
$dbyesterday = date("d.m.y", time() - 2*(60 * 60 * 24));
?>
<div class="container" style="padding-top: 80px">
<div id="table_admin" class="span7">
<h3 id="name" style="color: orange">Visitenliste</h3>
</br>
<table class="table table-responsive table-hover">
<thead>
<tr>
<th id="tc">Station</th>
<th id="tc">Patientennummer</th>
<th id="tc">Zimmer</th>
<th id="tc">Name</th>
<th id="tc">Katheterart</th>
<th id="tc">Anlagedatum</th>
<th id="tc"><?php echo $dbyesterday; ?></th>
<th id="tc"><?php echo $yesterday; ?></th>
<th id="tc"><?php echo $today; ?></th>
</tr>
</thead>
<?php
require_once('server.php');
// DB-Query für die Visitenliste
$sql = "SELECT dbo.patients.Patientennummer, Vorname, Nachname, Station, Zimmer, Katheterart, Anlagedatum FROM dbo.patients INNER JOIN dbo.cathinsert ON dbo.patients.Patientennummer = dbo.cathinsert.Patientennummer ORDER BY Station ASC, Zimmer ASC";
$visdbyes = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$dbyesterday') AS VisiteKind";
$visyes = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$yesterday') AS VisiteKind";
$vistod = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$today') AS VisiteKind";
$result = sqlsrv_query($connection, $sql);
$result_vdy = sqlsrv_query($connection, $visdbyes);
$result_vy = sqlsrv_query($connection, $visyes);
$result_vt = sqlsrv_query($connection, $vistod);
$data = array();
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){$data['row'] = $row;}
while($row = sqlsrv_fetch_array($result_vdy, SQLSRV_FETCH_ASSOC)) {$data['dby'] = $row;}
while($row = sqlsrv_fetch_array($result_vy, SQLSRV_FETCH_ASSOC)) {$data['yes'] = $row;}
while($row = sqlsrv_fetch_array($result_vt, SQLSRV_FETCH_ASSOC)) {$data['tod'] = $row;}
echo ("<tr class=\"clickable-row\" data-href=\"visitact.php?Patientennummer=".$row["Patientennummer"]."\">");
echo ("<td>".$data['row']["Station"]."</td>");
echo ("<td>".$data['row']["Patientennummer"]."</td>");
echo ("<td>".$data['row']["Zimmer"]."</td>");
echo ("<td>".$data['row']["Vorname"]." ".$data['row']["Nachname"]."</td>");
echo ("<td>".$data['row']["Katheterart"]."</td>");
echo ("<td>".$data['row']["Anlagedatum"]."</td>");
echo ("<td>".$data['dby']["VisiteKind"]."</td>"); //vorgestern
echo ("<td>".$data['yes']["VisiteKind"]."</td>"); // gestern
echo ("<td>".$data['tod']["VisiteKind"]."</td>"); //heute
?>
</table>
</div>
</div>
</body>
</html>
I hop you can help!
Thanks in advance,
dirk
I think You should use one query for every days, then check dates in while loop. You can also reduce 'VisiteKind' field in $data array:
$visd = "SELECT VisiteKind FROM dbo.visits";
$result_v = sqlsrv_query($connection, $visd);
$data = ['dby'=> [], 'yes'=> [], 'tod'=> []];
while($row = sqlsrv_fetch_array($result_v, SQLSRV_FETCH_ASSOC)) {
switch($row['VisiteKind']){
case $dbyesterday:
array_push($data['dby'],$row['VisiteKind']);
break;
case $yesterday:
array_push($data['yes'],$row['VisiteKind']);
break;
case $today:
array_push($data['tod'],$row['VisiteKind']);
break;
}
}
I am currently creating a calendar where you can see all users that are saved in the database for that day and the possibility to add an user per date.
I want to work with dates because I think it is easier to work with in the future.
So what I am doing: I save a date into the database combined to an userid.
While I am fetching the data from database into a table I am converting the dates to days and weeks and years. Just to see which day is at 2015/10/05.
So I get $day = Monday, $week = 41, $year = 2015
In the table I want to put the users to the matching day.
The calendar looks like this:
I am calling an if statement:
if ($day == 'Mon') {
// SELECT * FROM users WHERE datum=$date
// Fetch and echo the users name into that day
}
The database looks like this:
The weeks showed here in the database, maybe they can be used for a proper display? But I don't know I tried several things.
I am using this code for putting the database rows into a table:
$sql = "SELECT distinct(week),datum, van , tot FROM roosternew ORDER BY datum ASC";
$run_sql = mysqli_query($conn , $sql);
?>
<table class="table">
<thead>
<tr class="primary">
<th width="5%"><center>Week</center></th>
<th width="10%">Maandag</th>
<th width="10%">Dinsdag</th>
<th width="10%">Woensdag</th>
<th width="10%">Donderdag</th>
<th width="10%">Vrijdag</th>
<th width="10%">Zaterdag</th>
<th width="10%">Zondag</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($run_sql)) {
echo $row['datum'].'test';
$datum = $row['datum'];
$van = $row['van'];
$tot = $row['tot'];
$tijd = $van.' - '.$tot;
$date = new DateTime($datum);
$week = $date->format("W");
$dag = $date->format("D");
$jaar = $date->format("Y");
$newdate_ = new DateTime($datum);
$newdate = $newdate_->format('Y-m-d');
$week_start = new DateTime();
$week_start->setISODate($jaar,$week);
$thisdate_ = $week_start->format('d-m');
//Create plus button
$plus_button = ' <i class="fa fa-plus-square"></i><br/>';
//Plus button
$thisdate = '<div class="datetable"><div class="datetable">'.$thisdate_.'</div></div><br/>';
?>
<tr>
<td class="primary"><center><strong><?= $week; ?></strong><br/><?php echo $thisdate.'<h4><small>'.$jaar.'</small></h4>'; ?></center></td>
<td>
<?php
createPlusButton(0, $jaar,$week);
if ($dag == 'Mon') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(1, $jaar,$week);
if ($dag == 'Tue') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(2, $jaar,$week);
if ($dag == 'Wed') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(3, $jaar,$week);
if ($dag == 'Thu') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(4, $jaar,$week);
if ($dag == 'Fri') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(5, $jaar,$week);
if ($dag == 'Sat') {
getScheduleAdmin($newdate);
}
?>
</td>
<td>
<?php
createPlusButton(6, $jaar,$week);
if ($dag == 'Sun') {
getScheduleAdmin($newdate);
}
?>
</td>
</tr>
<? } ?>
</tbody>
</table>
The function getScheduleAdmin($newdate):
function getScheduleAdmin($newdate) {
require('connect.php');
$sql2 = "SELECT * FROM roosternew WHERE datum='$newdate'";
$run_sql2 = mysqli_query($conn , $sql2);
while ($row2 = mysqli_fetch_assoc($run_sql2)) {
$id_rooster_users = $row2['idusers'];
$sql= mysqli_query($conn,"SELECT * FROM users WHERE idusers='$id_rooster_users'");
$row = mysqli_fetch_array($sql);
$name = $row['name'];
$color = $row['color'];
$sql3 = "SELECT van,tot FROM roosternew WHERE idusers= '$id_rooster_users'";
$sql3_run = mysqli_query($conn,$sql3);
$sql3_array = mysqli_fetch_array($sql3_run);
$van_user = $sql3_array['van'];
$tot_user = $sql3_array['tot'];
$tijd_user = $van_user.' - '.$tot_user;
echo ''.$name.'<br/>'.'('.$tijd_user.')';
echo '<br/>';
}
}
The problem is described in the first image (the calendar), it will show me more than once the week and they won't merge.
I dont know how to merge the weeks so that it will be :
Something like that.
And not like this (situation right now):
if anyone knows a better way of doing this, please tell me.
SO i have form which consist of "Event Name" "Event Description" "Event Date" and checkbox "is important". When i check checkbox value "yes" its important, it sends to the sql value = "1" to table "is_important". Everything is all right, but i give the bootstrap style "bg-danger" for that "is_important" = 1 table and it doesnt show up. What's the problem?
You can see in the code:
<?php
if (isset($_POST['important'])) {
$error = array();
$success = array();
$eventTime = time();
$important = $_POST['important'];
$eventName = trim(mysql_real_escape_string($_POST['EventName']));
$eventDesc = htmlentities(trim(mysql_real_escape_string($_POST['EventDesc'])), ENT_QUOTES);
if (!isset($eventName) || empty($eventName)) {
$error['eventName'] = "Prasome ivesti ivykio varda";
} else if (strlen($eventName) > 32 || strlen($eventName) < 3) {
$error['eventName'] = "Ivykio pavadinimas turi buti tarp 3 ir 32 simboliu";
}
if (!isset($eventDesc) || empty($eventDesc)) {
$error['eventDesc'] = "Prasome ivesti ivykio aprasyma";
}
if (empty($error)) {
$sql = "INSERT INTO notes_list (title, description, timestamp,is_important) VALUES ('$eventName', '$eventDesc','$eventTime','$important')";
$result = mysqli_query($con, $sql);
$success[] = "SEKME !";
} else {
}
}
?>
<table class="table table-striped">
<thead>
<tr>
<th>Event name</th>
<th>Event description</th>
<th>Event date</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM notes_list ORDER BY id DESC LIMIT 10";
$result2 = mysqli_query($con, $query);
print_r($_POST);
if ($result2) {
while ($note = mysqli_fetch_assoc($result2)) {
?>
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
<td><?php echo $note['title']; ?></td>
<td><?php echo $note['description'] ?></td>
<td><?php echo date('l M jS', $note['timestamp']); ?></td>
</tr>
<?php
}
mysqli_free_result($result2);
}
/* close connection */
mysqli_close($con);
?>
</tbody>
</table>
Full Example in this picture:
https://www.dropbox.com/s/h650h2spy2487dm/chechbox.jpg?dl=0
This:
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
would render this:
<trclass='bg-danger'>
in case is_important is 1. You need a space there, before the class.
I am having trouble with getting my year to echo properly.
Example: I have 2 news articles one with a year of 2011 and the other 2012. They are splitting into the correctly "year" div. But when it comes to rendering out the year, it works. But 2011 and 2012 are stacked above each other. Something like this.
2012
2011
5.1.12 My news article
Where 2011 year is suppose to go
5.1.11 My news article
Here is my code.
<?
$startYear = 2010;
$endYear = 2012;
for($y = $endYear; $y > $startYear -1; $y--) { ?>
<?
$news = query("SELECT * FROM news_entries
WHERE title > ''
AND published = 1
AND date >= '" . mktime(0,0,0,0,0,$y) . "'
AND date < '" . mktime(0,0,0,0,0,$y+1) . "'
ORDER BY date DESC");
?>
The rest of the query.
<? if($news['total']>0) { ?>
<h3><? echo $y; ?></h3>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="first" width="125">Date</th>
<th>News Headline</th>
<th width="140"> </th>
</tr>
<? do { ?>
<tr>
<td><span><? echo date("F d, Y",$news['data']['date']); ?></span></td>
<td><? echo $news['data']['headline']; ?></td>
<td>Learn More</td>
</tr>
<? } while($news['data'] = mysql_fetch_assoc($news['object'])); ?>
<? }} ?>
<tr>
<td colspan="2" class="last"></td>
<td class="last"> Back to Top</td>
</tr>
</table>
I agree with Kato's comment. Typically, you get all of the results and iterate over them, printing a new header when the data changes.
Here's how this type of thing is usually handled (pseudocode):
$sql = "SELECT * FROM news_enteries ORDER BY date DESC";
// Prepare statement
$stmt = $pdo->prepare($sql);
// Bind variables
...
// Execute query
$stmt->execute() or die();
$year_header = "";
while ($row = $stmt->fetch()) {
$year = date("Y", strtotime($row['date']));
// Do we need a new year header?
if ($year_header <> $year) {
$year_header = $year;
// Print year header
echo $year_header;
}
// Process rest of the row
...
}