Re: Masking a reacuring result

From: Date: Sun, 19 Aug 2001 14:09:54 +0000
Subject: Re: Masking a reacuring result
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11519@lists.php.net to get a copy of this message
"Ron Gallant" <rongallant@email.com> wrote in message news:20010819121645.56511.qmail@pb1.pair.com... > I am querying a list with a date field. I want to order the list by the > date field and only show each days date once with the other fields showing. > > (row 1) 2001-08-19 - some text here. > (row 2) more text under same date. My date does not > show. > (row 3) 2001-08-20 - Lots of text today. > (row 4) Even more text here today. My date does not > show. > (row 5) Yes more text, date not showing. This seems to be a recurrent question in various guises; The idea is simple: sort by date (so all equal dates are together), then keep a temporary variable set to the last-seen date. When the date changes, output a new date value. ========== example.php ============ <?php mysql_connect("host", "user", "pwd") or die("Error connecting: ".mysql_error()); // return the 20 most recent items $query = "SELECT mydate,mytext " ."FROM table " ."ORDER BY mydate DESC " ."LIMIT 20"; $result = mysql_db_query("dbase", $query) or die("Error querying: ".mysql_error()); // show results in a table $lastdate = ""; echo "\n<table>"; while ($row = mysql_fetch_array($result)) { extract($row); if ($lastdate == $mydate) $t = ""; else $t = $lastdate = $mydate; echo "\n\t<tr><td>$t</td><td>$mytext</td></tr>"; } echo "\n<\table>"; ?> ===============================

« previous php.db (#11519) next »