Jump to content

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/153445-solved-create-own-forum/
Share on other sites

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

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?

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?

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 :D

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.