Here is a link to the page and the code involved. For some reason 2nd result of the category is not where its ment to be and i really don't know why as it works just fine on my other site and its the same code. But just now when i go to read it its not making the sence it used too.
demo
It should output like this.
demo
PHP:
<?php
$sql = "SELECT
category.`id`,
category.`category`,
category.`id` as `cat_id`,
topic.`title`,
topic.`id`,
topic.`about`,
COUNT(DISTINCT postcounting.`id`) AS `topiccount`,
COUNT(DISTINCT replycounting.`id`) AS `replycount`
FROM `forum-category`
AS `category`
LEFT JOIN `forum-topics`
AS `topic`
ON
category.`id` = topic.`category_id`
LEFT JOIN `forum-posts`
AS
`postcounting`
ON
topic.`id` = postcounting.`post-id`
LEFT JOIN `forum-reply`
AS
`replycounting`
ON
postcounting.`id` = replycounting.`reply-id`
GROUP BY
topic.`id`
ORDER BY
category.`order` DESC
";
///start result//
$result = mysql_query($sql) or die("<div class=\"main_block\"><div class=\"error_title\">Error</div><p>Error connecting to database</p></div>");
/// logic to handle the last category ///
// the last category
$last_cat = '';
// loop through records
while ($row = mysql_fetch_assoc($result)) {
// check if the category changed
if($row['category'] != $last_cat) {
// close previous category's table/divs (but not at the beginning of the loop)
if ($last_cat != '') {
echo '<h3>'.$row['category'].'</h3>';
echo ' <div class="table_heading_forum">
<div class="forum_header"><span class="header_item">Forum</span></div>
<div class="last_post_header"><span class="header_item">Last Posted</span></div>
<div class="topics_header"><span class="header_item">Topics</span></div>
<div class="replies_header"><span class="header_item">Replies</span></div>
</div>';
}
// set last_cat
$last_cat = $row['category'];
}
/*echo '<div class="category_header"><span class="cat_link"><a href="index.php"><a href="index.php?category='.$row['cat_id'].'">'.$row['category'].'</a></span></div>'; */
// start a new content block
$last_id = $row['id'];
// last post handleing //
$sql_last = "SELECT
topic.`title`,
post.`id` AS `id_post`,
post.`subject` AS `post_subject`,
post.`username` AS `post_user`,
post.`date` AS `post_date`,
reply.`reply-id`,
reply.`subject`,
reply.`username` AS `reply_user`,
reply.`date` AS `reply_date`,
GREATEST(post.`date`, reply.`date`) AS `latest_date`
FROM
`forum-topics`
AS
`topic`
LEFT JOIN
`forum-posts`
AS
`post`
ON
post.`post-id` = topic.`id`
LEFT JOIN
`forum-reply`
AS
`reply`
ON
reply.`reply-id` = post.`id`
WHERE
topic.`id` = ".$last_id."
GROUP BY
GREATEST(post.`date`, reply.`date`)
ORDER BY GREATEST(post.`date`, reply.`date`) DESC
LIMIT 1
";
///start result//
$result_last = mysql_query($sql_last);
$last_row = mysql_fetch_assoc($result_last);
$val = explode(" ",$last_row['latest_date']);
$date = explode("-",$val[0]);
$time = explode(":",$val[1]);
$test_date = "".$date[1]."-".$date[2]."-".$date[0]." ".$time[0].":".$time[1]."";
if ($test_date == "-- :") {
$date = "";
}
else {
$date = $test_date;
}
if ($last_row['reply_user'] == "") {
$last_user = $last_row['post_user'];
}
else {
$last_user = $last_row['reply_user'];
}
// print the first row for the current topic
printf('<div class="category_row">
<div class="forum_row">
<span class="row_title"><a href="index.php?topic=%s">%s</a></span>
<span class="row_item">%s</span>
</div>
<div class="last_post_row">
<span class="row_item">%s</span>
<span class="row_item">%s</span>
</div>
<div class="topics_row">
<span class="row_item">%s</span>
</div>
<div class="replies_row">
<span class="row_item">%s</span>
</div>
</div>', urlencode($row["id"]), $row["title"], $row["about"], $last_user, $date, $row["topiccount"], $row["replycount"]);
echo '<div class="comment_bar"></div>';
}
// close the block for the last category
if ($session->isAdmin() AND isset($_GET['admin_mode'])) {
echo '<div class="main_block"><h3>ADMIN: NEW Category</h3><div class="inside_block_special">';
if (!isset($_GET['post_category']) AND $session->isAdmin()) {
echo '<form action="index.php?post_category" method="post">';
echo '<p>New Category</p>';
echo 'Title: <input type="text" name="title"> Order: <input type="text" name="order"> <input type="submit">';
echo '</form>';
}
if (isset($_GET['post_category']) AND $session->isAdmin()) {
if ($_POST['title'] == "" OR $_POST['order'] == "") {
echo '<ul class="error">';
if ($_POST['title'] == "") {
echo "<li>forgot title</li>";
}
if ($_POST['order'] == "") {
echo "<li>forgot order</li>";
}
echo '</ul>';
echo '<form action="index.php?post_category" method="post">';
echo '<p>New Category</p>';
echo 'Title: <input type="text" name="title" value="'.$_POST['title'].'"> Order: <input type="text" name="order" value="'.$_POST['order'].'"> <input type="submit">';
echo '</form>';
}
else {
echo '<p>Success</p>';
$category = $_POST['title'];
$order = $_POST['order'];
$sql = sprintf("INSERT INTO `forum-category` (`category`, `order`) VALUES ('%s', '%s')",
mysql_real_escape_string($category),
mysql_real_escape_string($order));
$query = mysql_query($sql);
if(!$query) {
///// error out /////
echo "<p>There seems to have been a error in posting</p><p>Please try again later</p>";
}
}
}
echo '</div>';
echo '</div>';
}
?>
It should output like this.
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Start header -->
<head>
<!-- Charicter set -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Page Title -->
<title>Absolution Guild : Azjol-Nerub EU : forum</title>
<!-- Main stylesheet for the site -->
<style type="text/css" media="all">@import "stylesheet.css";</style>
<!-- This includes the ImageFlow CSS and JavaScript -->
<link rel="stylesheet" href="imageflow/imageflow.css" type="text/css" />
<!-- Stylesheet for forum pages -->
<style type="text/css" media="all">@import "forum/forum_style.css";</style>
<!--[if lt IE 7]>
<style media="screen" type="text/css">
.col1
{
width:100%;
}
</style>
<![endif]-->
<!-- Import the Scripts -->
<!-- Whos online dynamicly shows the current users logged onto the site -->
<script src="script/whosonline.js" language="javascript" type="text/javascript"></script>
<!-- End header -->
</head>
<!-- Start outputting the body -->
<body>
<!-- User controls -->
<div id="userbar">
<div id="userbar_inside">
<div id="userbar_username">Chiochan : Admin</div><div id="userbar_controls"><ul><li><a href="/forum/index.php?admin_mode">Edit</a></li><li><a href="../admin/index.php">Admin</a></li><li><a href="../process.php">Logout</a></li><li><a href="../useredit.php">Account</a></li><li><a href="/mail/index.php">Mail (0)</a></li></ul></div> <!-- inside user pannel -->
</div>
</div>
<!-- End of "user controls" --><div id="header_repeat">
<div id="header"><!-- Page header -->
<!-- Header image called by css -->
<!-- header span -->
<div id="header_left"></div>
<!-- Accessibility header that's only seen by screen readers or CSS-less browsers -->
<h1 class="nosee">Adult Baby Comforts</h1>
</div><!-- End of "header"-->
</div>
<div id="navagation"><!-- Main navagation bar -->
<!-- Navagation Links -->
<ul>
<li><a href="../index.php">Home</a></li><li class="active_link"><a href="../forum/index.php">Forum</a></li><li><a href="../chat/index.php">Chat</a></li><li><a href="../dkp/">DKP</a></li> </ul>
</div><!-- End of "navagation" -->
<div id="page_crumb">
Welcome to the forum.</div><div class="view_block"><span class="view_modes_active"><a href="index.php?view_mode=forum">Forum</a></span><span class="view_modes"><a href="index.php?view_mode=basic_search">Search</a></span><span class="view_modes"><a href="index.php?view_mode=statement">New Topic</a></span></div>
<h3>Class Forums</h3> <div class="table_heading_forum">
<div class="forum_header"><span class="header_item">Forum</span></div>
<div class="last_post_header"><span class="header_item">Last Posted</span></div>
<div class="topics_header"><span class="header_item">Topics</span></div>
<div class="replies_header"><span class="header_item">Replies</span></div>
</div><div class="category_row">
<div class="forum_row">
<span class="row_title"><a href="index.php?topic=33">Melee DPS</a></span>
<span class="row_item">Feel my blade, infidel</span>
</div>
<div class="last_post_row">
<span class="row_item"></span>
<span class="row_item"></span>
</div>
<div class="topics_row">
<span class="row_item">0</span>
</div>
<div class="replies_row">
<span class="row_item">0</span>
</div>
</div><div class="comment_bar"></div><h3>Tactics</h3> <div class="table_heading_forum">
<div class="forum_header"><span class="header_item">Forum</span></div>
<div class="last_post_header"><span class="header_item">Last Posted</span></div>
<div class="topics_header"><span class="header_item">Topics</span></div>
<div class="replies_header"><span class="header_item">Replies</span></div>
</div><div class="category_row">
<div class="forum_row">
<span class="row_title"><a href="index.php?topic=34">Naxxramas</a></span>
<span class="row_item">No description has been entered for this forum.</span>
</div>
<div class="last_post_row">
<span class="row_item"></span>
<span class="row_item"></span>
</div>
<div class="topics_row">
<span class="row_item">0</span>
</div>
<div class="replies_row">
<span class="row_item">0</span>
</div>
</div><div class="comment_bar"></div><h3>Absolution Guild Forums</h3> <div class="table_heading_forum">
<div class="forum_header"><span class="header_item">Forum</span></div>
<div class="last_post_header"><span class="header_item">Last Posted</span></div>
<div class="topics_header"><span class="header_item">Topics</span></div>
<div class="replies_header"><span class="header_item">Replies</span></div>
</div>
<div class="category_row">
<div class="forum_row">
<span class="row_title"><a href="index.php?topic=35">AFK</a></span>
<span class="row_item">If u require time out please let us know here.</span>
</div>
<div class="last_post_row">
<span class="row_item"></span>
<span class="row_item"></span>
</div>
<div class="topics_row">
<span class="row_item">0</span>
</div>
<div class="replies_row">
<span class="row_item">0</span>
</div>
</div>
<div class="category_row">
<div class="forum_row">
<span class="row_title"><a href="index.php?topic=1">Members Discussion</a></span>
<span class="row_item">General Forums for open discussions</span>
</div>
<div class="last_post_row">
<span class="row_item">Chiochan</span>
<span class="row_item">03-10-2009 01:55</span>
</div>
<div class="topics_row">
<span class="row_item">2</span>
</div>
<div class="replies_row">
<span class="row_item">0</span>
</div>
</div>
<div class="comment_bar"></div>
<!-- Footer -->
<div id="footer">
Absolution - Azjol-Nerub EU
</div>
<!-- End of footer -->
</body>
</html>