$q = new mydb;
// get the maxdate (i.e. current)
$maxdate = null;
$sql = "SELECT DATE_FORMAT(MAX(Date), '%Y%m%d') as DateString FROM News WHERE Active = 1";
if ($q->query($sql)) {
if ($q->num_rows()) {
while($q->next_record()) {
$maxdate = $q->f('DateString');
}
}
}
// use qstring, if it's there
$thedate = null;
$sql = "SELECT NewsID, Title, Body, Active, ImagePath, ImageBorder, ImageTitle, Date, DATE_FORMAT(Date, '%Y%m%d') as DateString";
$sql .= " FROM News WHERE Active = 1";
$sql .= " ORDER BY Date DESC";
if (isset($_GET['date'])) {
$finddate = $_GET['date'];
if ($q->query($sql)) {
if ($q->num_rows()) {
while($q->next_record()) {
if ($q->f('DateString') == $finddate) $thedate = $q->f('DateString');
}
}
}
}
if (!isset($thedate)) { // they didn't pass one or we didn't find it
$thedate = $maxdate;
}
// Now we have $thedate, loop
if ($q->query($sql)) {
if ($q->num_rows()) {
while($q->next_record()) {
if ($q->f('DateString') == $thedate) {
// date
$rawdate = $q->f('DateString');
$displayDate = date("j F Y", mktime(0,0,0, substr($rawdate,4,2), substr($rawdate,6,2), substr($rawdate,0,4)));
// title?
$title = stripslashes($q->f('Title'));
// image?
$image = null;
if (!is_null($q->f('ImagePath'))) {
$image = '
f('ImageTitle'))) {
$image .= ' title="' . $q->f('ImageTitle') . '"';
}
$image .= ' alt=""';
if (!is_null($q->f('ImageBorder'))) {
$image .= ' border="' . $q->f('ImageBorder') . '"';
}
$image .= ' />';
}
// body
$pattern = chr(13) . chr(10) . chr(13) . chr(10);
$body = '
CreatePageFooter(); ?>
' . eregi_replace($pattern, "
\n", stripslashes($q->f('Body'))) . '
'; ?>if ((strlen($image) > 0) /* && ($thedate == $maxdate)*/ ) echo "$image "; ?> //if (strlen($title) > 0) echo "
$title
\n"; ?> = $displayDate ?>= "\n"; ?> = $body ?> } } $q->seek(); } } // This is a list of links for previous content. if ($q->num_rows() > 1) { ?>
previous news:
while($q->next_record()) { $rawdate = $q->f('DateString'); $displayDate = date("j F Y", mktime(0,0,0, substr($rawdate,4,2), substr($rawdate,6,2), substr($rawdate,0,4))); // if ($q->f('DateString') < $thedate) { // or, you know, not equal to it... if ($q->f('DateString') != $thedate) { // or, you know, less than it... ?>= $displayDate ?>
} else { ?>= $displayDate ?> (shown)
// or, you can NOT display the current one... } } ?>
}
?>
while($q->next_record()) { $rawdate = $q->f('DateString'); $displayDate = date("j F Y", mktime(0,0,0, substr($rawdate,4,2), substr($rawdate,6,2), substr($rawdate,0,4))); // if ($q->f('DateString') < $thedate) { // or, you know, not equal to it... if ($q->f('DateString') != $thedate) { // or, you know, less than it... ?>= $displayDate ?>
} else { ?>= $displayDate ?> (shown)
// or, you can NOT display the current one... } } ?>