PDA

View Full Version : Little help with layout of a print




Cabbit
Jan 29, 2008, 05:00 PM
working on a little problem here during my print out i get the table headers every single time and the bottom is never printed.


<?php
$sql = "SELECT
category.`id`,
category.`category`,
topic.`title`,
topic.`id`,
topic.`about`,
topic.`lastpost`,
topic.`lastposttime`,
topic.`lastid`,
topic.`lasttopic`,
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.`id`
";
///start result//
$result = mysql_query($sql) or die("Query failed($sql): " . mysql_error());
/// logic to handle the last category ///
$last_cat = '';
/// first counter for row colours///
$i = 0;
/// second counter for row colours ///
$m = 0;
/// start loop///
WHILE ($row = mysql_fetch_array($result)) {
/// if statement for handleing category rows///
if($row['category'] != $last_cat) {
$last_cat = $row['category'];
////The title of the block element (the catagory)////
printf( "<div class=\"title\"><h3>%s" . "</h3></div>", $row["category"]);
}
/// printing the rest of the table////
print "<div class=\"content\"><div class=\"content_text\">";
print '<table width="100%" border="0" cellpadding="3" cellspacing="0" >';
print '<tr class="page_title"><td width="50%">Forum</td><td width="10%">Topics</td><td width="10%">Replies</td><td width="30%">Last Posted by</td></tr>';
if($i++ % 2)
{
print '<tr class="wight">';
}
else
{
print '<tr class="other">';
}
printf("<tr><td><a href=\"forum_topic.php?id=%s&title=%s\">%s</a>" . "</td><td>%s" . "</td><td>%s" . "</td><td>%s" . "</td></tr>", $row["id"], $row["title"], $row["title"], $row["topiccount"], $row["replycount"], $row["lastpost"]);
/// the second row colour changer ////
if($m++ % 2)
{
print '<tr class="wight">';
}
else
{
print '<tr class="other">';
}
printf("<td><font size=\"-1\">%s" . "</font></td><td></td><td></td><td><font size=\"-1\">%s" . "<br /><a href=\"forum_topic_view.php?catagory=%s&title=%s&id=%s\">%s</a>" . "</font></td></tr>", $row["about"], $row["lastposttime"], $row["id"], $row["title"], $row["lastid"], $row["lasttopic"]);

/// finish the table ///
print '</table></div></div>';
}
$last_id = $row['about'];
if($row['about'] != $last_id) {
////the bottom////
print '<div class="bottom_content"><div class="btm_text">Add me</div></div>';
}
/////////////////////content ends////////////////////////
}



else {
///not logged in///
include("page_blocks/login.php");
/////////////////////content ends////////////////////////
}
?>



angelwatt
Jan 29, 2008, 05:56 PM
First note, you should format the code a little better and match up brackets. It would make reviewing the code much easier.

For the bottom where you have,
$last_id = $row['about'];
if($row['about'] != $last_id) {
...
You set the two variables to be equal, then you check if they are not equal. This'll never happen, which is why you never get a bottom. Unless I'm missing something. Not sure about the title part though yet. I'll stare at it a little longer to what's up there. You may want to try and print out some variables to make sure they equal what you think they do.

Cabbit
Jan 29, 2008, 06:10 PM
i should point out this came form a tabled layout that worked well im just converting it to match the new layout of the site.