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
<?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>';
}
?>