DEVILofDARKNESS Posted April 10, 2009 Share Posted April 10, 2009 Hi, I want to make my own forum so I don't have to mess in the scripts from others. Because I've made some phpscripts and I always had to change and add things while I was building the script, I want that everything works fine from the beginning and I don't have to add or change things. So My question is, is this a good main page for a forum? Or have I forgot something? It is not much code only some ideas actually, but I will try to start with the code soon enough. <?php function show_all_categories () {} //Shows every category in database. function open_categorie() { show_topics() } //Open selected category. //Starts function show_topics. function close_categorie() {} //Close selected category. function show_topics() {} //Shows every topic from a category. ?> <html> <head> <title>Forum</title> </head> <body> <?php show_all_categories(); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/ Share on other sites More sharing options...
waynew Posted April 10, 2009 Share Posted April 10, 2009 If you're going to use functions and not classes, at least include them via another file <?php require_once("inc/functions.php"); ?> <html> <head> <title>Forum</title> </head> <body> <?php show_all_categories(); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-806198 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 10, 2009 Author Share Posted April 10, 2009 Are classes better to use than functions in this case? I'm not well known with classes, so I will google for it Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-806790 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 I believe it depends what you're doing tbh. If you have a group of functions that are closely related, then a class can be useful to keep it organised. Otherwise, a function is quicker, requires less memory and less code. Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-806864 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 11, 2009 Author Share Posted April 11, 2009 Ok, I've made a function which shows every category, how can I make the function that all the cat. are displayed and the one where you have clicked on is collapsed? Main page: <?php require_once './functions.php'; $action = $_GET['a']; switch($a) { case "main": show_all_categories(); break; case "showtopics1": open_categorie(1); break; case "showtopics2": open_categorie(2); break; } ?> <html> <head> <title>Forum</title> </head> <body> <?php show_all_categories(); ?> </body> </html> Function Page: <?php require_once '../config.php'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); function show_all_categories () { //Shows every category in database. echo "<table border='1'>"; $query = "SELECT * FROM categories"; $result = mysql_query($query); while($categories = mysql_fetch_array($result)) { echo "<tr><td><table border='0'><tr><td><a href='main.php?a=showtopics" . $categories['category_id'] . "'>" . $categories['category_name'] . "</a></td></tr><tr><td>" . $categories['category_description'] . "</td></tr></table></td></tr>"; } echo "</table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807178 Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 If you have a group of functions that are closely related, then a class can be useful to keep it organised. That's what namespaces are supposed to be for. Using class just as a container for related functions is a bit of an overkill. Otherwise, a function is quicker Oh it is? Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807182 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Meh, that's what I use classes for. And yeah, classes apparently have a bit of an overhead in initialisation, or so I am told. Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807184 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 11, 2009 Author Share Posted April 11, 2009 That doesn't solve my problem :-( Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807223 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 What do you mean by "collapsed" exactly? Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807268 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 11, 2009 Author Share Posted April 11, 2009 If you click on it, the topics are shown, for example if U would click on Category 2 you would get: Category 1 Category 2 topic 2.1 topic 2.2 ... Category 3 Category 3 ... Or is it better to just load a new window with the Category Title, and the topics? Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807337 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 I'd personally go for the latter. I have actually made my own forum, but I didn't use topics, I just have subjects, like one big topic. You can check it out here: http://www.jackpf.co.uk/bin/beta/index.php?action=forum if you want. It'd be interested to compare Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807340 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 11, 2009 Author Share Posted April 11, 2009 I see, if I can't find why my version won't work, I will probably do the same as you did it. Here's the prob: If I type as $_GET: a=main or I let it blank, it works fine and gives me every challenge, but If I click on the link (?a=showtopics2) it won't work :-( : this is the main code: <?php require_once './functions.php'; $action = $_GET['a']; switch($action) { case "main": show_all_categories(); break; case "showtopics1": open_category(1); break; case "showtopics2": open_category(2); break; default: show_all_categories(); break; } ?> <html> <head> <title>Forum</title> </head> <body> </body> </html> And this is the function code: <?php require_once '../config.php'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); function show_all_categories () { //Shows every category in database. echo "<table border='1'>"; $query = "SELECT * FROM categories"; $result = mysql_query($query); while($categories = mysql_fetch_array($result)) { echo "<tr><td><table border='0'><tr><td><a href='main.php?a=showtopics" . $categories['category_id'] . "'>" . $categories['category_name'] . "</a></td></tr><tr><td>" . $categories['category_description'] . "</td></tr></table></td></tr>"; } echo "</table>"; } function open_category($category) { //Open selected category. //Starts function show_topics. $query = "SELECT category_name FROM categories WHERE category_id='$category'"; $result = mysql_query($query); list($categoryname) = mysql_fetch_row($result); echo "<table border='1'><tr><td>" . $categoryname . "</td></tr>"; echo "<tr><td>" . $topic['topic_name'] . "</td></tr>"; show_topics($category); echo "</table>"; } function close_categorie() {} //Close selected category. function show_topics($category) {} //Shows every topic from a category. $query = "SELECT * FROM topics WHERE category_id = '$category'"; $result = mysql_query($query); while($topics = mysql_fetch_array($result)) { echo "<tr><td><table border='0'><tr><td>" . $topics['title'] . "</td></tr></table></td></tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807351 Share on other sites More sharing options...
DEVILofDARKNESS Posted April 11, 2009 Author Share Posted April 11, 2009 Ok, I found it This is (for the moment) solved Quote Link to comment https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/#findComment-807369 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.