Re: Retrieving data woes
| From: | Hugh Bothwell | Date: | Mon, 10 Dec 2001 16:34:21 +0000 |
| Subject: | Re: Retrieving data woes | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14909@lists.php.net to get a copy of this message | ||
"Andres Sulleiro" <andres@sulleiro.com> wrote in message
news:002001c18193$eacb4450$6b00a8c0@iconstlouis.com...
> I have a db table that has these columns:
> id, date, time, title, body
>
> some of the rows can have the same "date" and want to output the data
> according to "date". Like so:
>
> dateA
> timeA1, titleA1
> bodyA1
>
> timeA2, titleA2
> bodyA2
>
> dateB
> timeB1, titleB1
> BodyB1
In your SQL request, sort by date. When printing the output,
keep track of the previous date - only print the date if it
changes. Something like
$conn = mysql_pconnect($host, $usr, $pwd);
mysql_select_db("mydb");
$sql = "SELECT id,date,time,title,body FROM mytable ORDER BY date DESC";
$res = mysql_query($sql);
$date = "previous date";
while($row = mysql_fetch_array($res)) {
if ($date != $row["date"]) {
$date = $row["date"];
echo "<br>$date";
}
echo "<p>".$row["time"]." ".$row["title"];
echo "<br>".$row["body"];
}