"Sebastian" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>[snip]
> $result = $db->sql("SELECT * FROM $news GROUP BY time DESC LIMIT
> $_GET[page], $pagelimit");
> while($row = mysql_fetch_row($result)) {
>
> echo "$row[title] <br/> Written by $row[author] <br/> $row[text]";
> }
>
> I'd like to sort the results by day, example:
>
> Monday's Articles:
> all rows that are posted on Monday.....
>
> Tuesday's Articles:
> all rows that are posted on Tuesday ...
If you're sorting in descending order (as your
query seems to intend), shouldn't it be
Wednesday ... Tuesday ... Monday?
$query =
"SELECT title, author, text, tstamp, DAYNAME(tstamp) AS day "
."FROM news "
."SORT BY tstamp DESC "
."LIMIT {$_GET['page']}, $pagelimit";
$result = $db->sql($query);
$first = true;
$lastday = "";
while($row = mysql_fetch_array($result)) {
if ($row['day'] != $lastday) {
$lastday = $row['day'];
if ($first)
$first = false;
else
echo "</ul>";
echo date("l M j", $row['tstamp']) . "<br/><ul>";
}
echo
"<li><b>{$row['title']}</b><br/>"
."Written by {$row['author']}<br/>"
."{$row['text']}</li>";
}
if ($first)
echo "No results returned!<br/>";
else
echo "</ul>";
In production, I would rewrite this to
separate the logic from the presentation...
but if you trace through it, this should
give you a good idea of how to proceed.
--
Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada
v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+
PE++ Y+ PGP+ t-- 5++ !X R+ tv b++++ DI+++ D-(++) G+ e(++) h-- r- y+
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php