PDA

View Full Version : How to list forum categories on a non-vb page


Raptor
04-11-2001, 04:20 AM
I saw this on another post (made for v1.1.5)

<?php
require("forum/admin/config.php3");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query = "SELECT * FROM CATEGORY ORDER BY title ASC";
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<FONT SIZE=\"1\" FACE=\"Verdana\"> °
<A HREF=\"http://digital-forums.com/forum/index.php3?categoryid=$latest_array[categoryid]\">$latest_array[title]</A></FONT><BR>";
}

?>

But I just get this error msg:
Warning: Supplied argument is not a valid MySQL result resource in /home/dforums/public_html/list_categories.php3 on line 7

I'm using v2 beta 5 - can someone please get this working for me

thanks in advance !

Wayne Luke
04-11-2001, 04:30 AM
Here this shows the first two levels of forums...


<?php
require("global.php");
//Forum info
$forums=$DB_site->query('SELECT * FROM forum WHERE displayorder<>0 AND active=1 ORDER BY parentid,displayorder');
while ($forum=$DB_site->fetch_array($forums)) {
if ($forum[parentid] == -1) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"2\"><b><a href=\"http://sitepointforums.com/forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a></b></font><br>");
if ($forum[allowposting] == 0) {
$parent=$forum[forumid];
$subforums=$DB_site->query("SELECT * FROM forum WHERE displayorder<>0 AND active=1 AND parentid=".$parent." ORDER BY displayorder");
while ($subforum=$DB_site->fetch_array($subforums)) {
echo ("&nbsp;&nbsp;<font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://sitepointforums.com/forumdisplay.php?forumid=".$subforum[forumid]."\">".$subforum[title]."</a></font><br>");
}
}
}
}
$DB_site->free_result($forums);
unset($forum);

?>

Raptor
04-11-2001, 05:11 PM
this is great thanks

couple of things:

Only works when calling the script when its in the /forum dir. But gives Fatal error: Failed opening required './admin/config.php3' (include_path='.:/usr/local/lib/php') in /home/dforums/public_html/forum/global.php3 on line 49 when outside the forum dir - is this something to do with the chdir command ?

And how to display topics without the sub topics ?

Many thanks

Raptor
04-11-2001, 05:17 PM
ok fixed the first part :)

chdir("/home/dforums/public_html/forum");
require("global.php3");

now how to list just the topics and not the sub topics - i'll have a go at doing it myself while awaiting help from you guys :)

Raptor
04-11-2001, 05:20 PM
ok i did it - is the code correct or is there anything in there that doesn't need to be there ?

<?php
chdir("/home/dforums/public_html/forum");
require("global.php3");
//Forum info
$forums=$DB_site->query('SELECT * FROM forum WHERE displayorder<>0 AND active=1 ORDER BY parentid,displayorder');
while ($forum=$DB_site->fetch_array($forums)) {
if ($forum[parentid] == -1) {
echo ("<font face=\"Verdana\" size=\"2\"><b><a href=\"http://digital-forums.com/forum/forumdisplay.php3?forumid=".$forum[forumid]."\">".$forum[title]."</a></b></font><br>");
if ($forum[allowposting] == 0) {
$parent=$forum[forumid];

}
}
}
$DB_site->free_result($forums);
unset($forum);

?>

trilizio
04-11-2001, 05:26 PM
WITH SUB CATEGORIES

<?
require("/home/dforums/public_html/forum/global.php");
//Forum info
$forums=$DB_site->query('SELECT * FROM forum WHERE displayorder<>0 AND active=1 ORDER BY parentid,displayorder');
while ($forum=$DB_site->fetch_array($forums)) {
if ($forum[parentid] == -1) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"2\"><b><a href=\"http://www.yourdomain.com/forum/forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a></b></font><br>");
if ($forum[allowposting] == 0) {
$parent=$forum[forumid];
$subforums=$DB_site->query("SELECT * FROM forum WHERE displayorder<>0 AND active=1 AND parentid=".$parent." ORDER BY displayorder");
while ($subforum=$DB_site->fetch_array($subforums)) {
echo (" <font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://www.yourdomain.com/forum/forumdisplay.php?forumid=".$subforum[forumid]."\">".$subforum[title]."</a></font><br>");
}
}
}
}
$DB_site->free_result($forums);
unset($forum);

?>


WITHOUT SUB CATEGORIES

<?
require("/home/dforums/public_html/forum/global.php");
//Forum info
$forums=$DB_site->query('SELECT * FROM forum WHERE displayorder<>0 AND active=1 ORDER BY parentid,displayorder');
while ($forum=$DB_site->fetch_array($forums)) {
if ($forum[parentid] == -1) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"2\"><b><a href=\"http://www.yourdomain.com/forum/forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a></b></font><br>");
}
}
$DB_site->free_result($forums);
unset($forum);

?>

trilizio
04-11-2001, 05:27 PM
Thats should work. If it doesn't then I dunno ;)

the_sisko
04-11-2001, 07:46 PM
Great
..but it shows my private forums and categories to normal users!!!

Wayne Luke
04-11-2001, 09:46 PM
You will have to add a WHERE clause in there to exclude private categories and forums by checking the forums private status.

I have a simple toggle switch in my database called "showactive" if it is true then we show it, if not we don't. The reason for this is we don't want some forums showing up in external scripts even if they are public like General Chit Chat forums and Member only forums.

Raptor
04-11-2001, 10:07 PM
could you list the code please ?

Wayne Luke
04-12-2001, 12:31 AM
All you have to do is add a field to the database called showactive. Set the properties for each forum, I did mine through PHPMyAdmin. Then add "where showactive=1" to any query you want it to have effect.