liquidspaceman Posted February 14, 2010 Share Posted February 14, 2010 Hi Folks, I am having trouble displaying the category name of my forum. For example, say I have two categories and one is named PHP CODING and the other is named JAVA CODING - If you are in the Java forum I want it to say JAVA FORUM on the top. I use HTML templates separately from the PHP. I would post the code that's "NOT WORKING" but I've tried about 10 different ways and none of them work. I am posting my original forum code without my modifications. Is there any way one of you can modify this code so that I can display "which forum" the user is in and then call it on my HTML template as SC_CURRENT_CATEGORY? I will bow down on my knees to you if you can help. As I said, I'd post the code that's "NOT WORKING" but then I'd be posting 10 different files. I'm not trying to be lazy or anything. I just wouldn't know which file to post here. If you prefer me to post my nonworking code I will do that, which one, I don't know. This is the code that DOES NOT display what category you are currently browsing. The few times I have modified this code I turned up with each post repeating 10 times. /******************************************************** * read data from user * ********************************************************/ if ($pg == "") { $pg = 1; } $row_per_page = $forum_num_topics; $offset = ($pg - 1) * $row_per_page; /******************************************************** * open connection to mysql server * ********************************************************/ mysql_connect($db_host, $db_user, $db_password); mysql_select_db($db_name); /******************************************************** * get data from table tbl_forum_category * ********************************************************/ $sql = "select * from tbl_forum_category"; $result = mysql_query($sql); $category = ""; while ($data_ctg = mysql_fetch_array($result)) { $ctg_id = $data_ctg["id"]; $ctg_name = $data_ctg["name"]; $ctg_code = $data_ctg["code"]; if ($ctg == "") { $ctg = $ctg_id; } if ($i == 0) { $category .= "<tr>\n"; } $category .= "<td width=50% align=left><font class=arial><a href='forum.php?pg=1&ctg=$ctg_id'><LI> <B>$ctg_name</B></a></font></td> "; if ($i == 1) { $category .= "</tr>\n"; } $i = ($i + 1) % 2; } if ($i == 1) { $category .= "</tr>\n"; } $ctg_len = strlen($category); $category = substr($category, 0, $ctg_len - 2); /******************************************************** * get total row in table tbl_forum * ********************************************************/ $sql = "select tbl1.id "; $sql .= "from tbl_forum as tbl1, tbl_user as tbl2 "; $sql .= "where (tbl1.status='online') and (tbl1.id_writer=tbl2.id) and "; $sql .= "(tbl1.id_category='$ctg') and (tbl1.id_parent='0') "; $result = mysql_query($sql); $total_row = mysql_num_rows($result); /******************************************************** * get data from table tbl_forum * ********************************************************/ $sql = "select tbl1.*, tbl2.login as writer_name, tbl2.code as writer_code, tbl1.numread, tbl3.color "; $sql .= "from tbl_forum as tbl1, tbl_user as tbl2, tbl_user_conf as tbl3 "; $sql .= "where (tbl1.status='online') and (tbl1.id_writer=tbl2.id) and "; $sql .= "(tbl1.id_category='$ctg') and (tbl1.id_parent='0') and (tbl3.id_user=tbl2.id) "; $sql .= "order by tbl1.lastpost desc limit $offset, $row_per_page"; $result = mysql_query($sql); $trow = mysql_num_rows($result); $row_start = $offset + 1; $row_end = $offset + $trow; $num_row = $row_start. "-". $row_end; if ($trow == 0) { $num_row = "0"; } $classifieds = ""; $i = 0; while ($data_cls = mysql_fetch_array($result)) { $id = stripslashes($data_cls["id"]); $subject = stripslashes($data_cls["subject"]); $cdate = stripslashes($data_cls["lastpost"]); $code = stripslashes($data_cls["code"]); $writer_name = stripslashes($data_cls["writer_name"]); $writer_code = stripslashes($data_cls["writer_code"]); $id_writer = stripslashes($data_cls["id_writer"]); $tcolour = stripslashes($data_cls["color"]); $views = stripslashes($data_cls["numread"]); $colour = $$tcolour; $subject = "<font class='arialbig'><a href='forum_read.php?id=$id&code=$code&ctg=$ctg'>$subject</font><font class='arial'></a>"; $writer = "<font class='arial'><a href=user_profile.php?id=$id_writer&code=$writer_code style='color:$colour'>$writer_name</a></font>"; $date = "<font class='arialsmall'>". timestamp2full($cdate). "</font>"; /******************************************************** * get data from table tbl_forum * ********************************************************/ $sql2 = "select id from tbl_forum where id_parent='$id'"; $result2 = mysql_query($sql2); $num_response = mysql_num_rows($result2); $totalresponses = $num_response; /******************************************************** * generate table * ********************************************************/ if ($i == "0") { $forum .= "<tr>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#FFFFFF' width=8> <img src=images/bullet2.gif></td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#FFFFFF'>$subject</td>\n"; $forum .= "<td align='center' valign='middle' bgcolor='#FFFFFF'><font class=arialsmall>$totalresponses</font></td>\n"; $forum .= "<td align='center' valign='middle' bgcolor='#FFFFFF'><font class=arialsmall>$views</font></td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#FFFFFF'>$writer</td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#FFFFFF'>$date</td>\n"; $forum .= "</tr>\n"; $i = 1; } else { $forum .= "<tr>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#DDDDDD' width=8> <img src=images/bullet2.gif></td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#DDDDDD'>$subject</td>\n"; $forum .= "<td align='center' valign='middle' bgcolor='#DDDDDD'><font class=arialsmall>$totalresponses</font></td>\n"; $forum .= "<td align='center' valign='middle' bgcolor='#DDDDDD'><font class=arialsmall>$views</font></td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#DDDDDD'>$writer</td>\n"; $forum .= "<td align='left' valign='middle' bgcolor='#DDDDDD'>$date</td>\n"; $forum .= "</tr>\n"; $i = 0; } } /******************************************************** * generate page navigator * ********************************************************/ $total_page = $total_row / $row_per_page; if (($pg > $total_page + 1) || ($pg <= 0)) { header("Location: forum.php?pg=1&ctg=$ctg"); exit; } /******************************************************** * page : next * ********************************************************/ $tmp = $pg; if ($tmp < $total_page) { $pg = $tmp + 1; $next = "<a href='forum.php?pg=$pg&ctg=$ctg' style='color:#FFFFFF'><b>Show next $row_per_page topics</b></a>"; } else { $next = ""; } /******************************************************** * page : prev * ********************************************************/ if ($tmp > 1) { $pg = $tmp - 1; $prev = "<a href='forum.php?pg=$pg&ctg=$ctg' style='color:#FFFFFF'><b>Show prev $row_per_page topics</b></a>"; } else { $prev = ""; } /******************************************************** * generate output page * ********************************************************/ $tpl = new scTemplate("templates/forum_toc.html"); $tpl->replace("SC_SI_BANNER", show_banner()); $tpl->replace("SC_SI_ADS", show_ads()); $tpl->replace("SC_SI_MENU", show_menu(7)); $tpl->replace("SC_SI_SEARCH", show_search()); $tpl->replace("SC_SI_NEWS", show_news()); $tpl->replace("SC_SI_MEMBER", show_member()); $tpl->replace("SC_SI_CALENDAR", show_calendar()); $tpl->replace("SC_SI_BOTTOM", show_bottom()); $tpl->replace("SC_SI_COPYRIGHT", show_copyright()); $tpl->replace("SC_CATEGORY", $category); $tpl->replace("SC_FORUM", $forum); $tpl->replace("SC_NUM", $num_row); $tpl->replace("SC_TOT", $total_row); $tpl->replace("SC_PREV", $prev); $tpl->replace("SC_NEXT", $next); $tpl->replace("SC_CTG", $ctg); $tpl->replace("SC_CODE", $ctg_code); $tpl->write(); Link to comment https://forums.phpfreaks.com/topic/192067-having-trouble-with-message-forum-displaying-category-name/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.