Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » It's time to learn me stuff

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
It's time to learn me stuff
23yrold3yrold
Member #1,134
March 2001
avatar

Okay, I just blasted through a reference of the PHP language and skimmed some MySQL docs. PHP is easy enough; reminds me of Lua. :) I have two specific things I'd like to know how to do with these things:

1) I want to make some simple forums. I get the basic idea; user types info into an HTML forum, PHP script takes the info and stuffs it in a MySQL database, then retrieves it from said database when someone feels like reading the thread, right? I kind of need a basic outline on how I would go about organizing that though, since I get the feeling it's a little more complicated than that. I know there's plenty of guys here who have done this (not least of which is Matthew :)) so could someone give me some pointers on how to begin? I don't feel like using phpBB or something like that; I want to make my own. :) Nothing fancy. If I could make something like Oscar has set up on acc.online and build on that, cool.

2) Managing new content. Let's say I want to add news to the front page, or keep a gallery of images/artwork that I add to from time to time. Would that work a lot like, say, the IotD submission page is set up? I would make a page for my own personal use that would upload images and description, and it would be inserted into the gallery in some intelligent fashion? Sometimes I hear people talk about programs they use for adding news to their sites or something ... not sure if that's just my imagination ...

I'm going to keep reading MySQL stuff now (if there's a good tut let me know), but I have other stuff to do today too (which is why I'm not on Battle.Net ;)) so if you guys could help me out, cool.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Kanzure
Member #3,669
July 2003
avatar

1) I'm your guy.
2) I'm also your guy. You're looking for a Content Management System. Attached. Good luck. I have a message board with it, too. (In the admin control panel, addpage.php, clicky on mPortBoard.) If you want to try it out, edit /admin/config.php to fit your MySQL needs. Then upload, and go to /install.php...It should be pretty self explanatory from there on. You have to enable a layout, layouts, I suggest "special blue". In there, if you search for mPortBoard, you're bound to find my code for it.

Please note, I haven't worked on 'mPort' - my content management system - in months. I'm working on something new of the likes, so let's not have everybody insult me at once for my crummy code :P

Billybob
Member #3,136
January 2003

1) Start a table called "posts" with the following fields:
Sub-Forum ID(INT), Thread ID(INT), post id(INT), owner id (INT), subject(TEXT), message(TEXT), date(DATETIME).

that should be a basic setup, methinks. Sub Forum id would be the id of the form you're posting in (off-topic for example). Thread id is the id of the thread the post is in. post id is a unique id given to every post. Owner id is the member # of the poster. you know what the rest is.

When you make that table, sub-forum id, thread id, and post id will probably be indexes. post id is unique. Post id also should be set to auto-increment.

You'll also need tables to store information about threads, sub-forums (could combined with the general settings stuff as well), members, etc...

Hope that helps some.

and don't forget your htmlentities and addslashes ;)

Kanzure
Member #3,669
July 2003
avatar

Here's some more info.

MySQL Snuff:

database "bob"

table posts
 id bigint 255
 replyToId bigint 255
 author varchar 255
 text blob

<?
mysql_connect("localhost", "root", "");
mysql_select_db("bob");

$sql = mysql_query("SELECT * FROM posts");
while($sr = mysql_fetch_array($sql)) {
 $id = $sr['id'];
 $replyId = $sr['replyToId'];
 $author = $sr['author'];
 $text = $sr['text'];
 print "<!--$id--><i><b>$author</b> says</i>:<br />$text";
}
?>

The form? You're on your own ;D Always glad to help a fellow membor out. Well...no, no, disregard that. :P

23yrold3yrold
Member #1,134
March 2001
avatar

Okay, I'm going to talk in C++ here. So I'd do something like this?

1class CPoster {
2 int member_id;
3 string sig;
4 int post_count;
5 int date_joined;
6 string avatar_url;
7 // other minor preferences
8}
9 
10class CPost {
11 int poster_id;
12 string content;
13}
14 
15class CThread {
16 int thread_id;
17 vector<post> posts;
18 int forum_id; // off topic, programming, etc.
19
20}
21 
22vector<CThread> threads;
23vector<CPoster> posters;

And would I need seperate vectors for referencing posts by poster (so you can see a member's recent activity) and threads by forum (so when you go to OT you only see the OT threads), etc? Have I got that about right? Is the translation to PHP/MySQL relatively minor?

I'll contemplate your posts too; took me a while to type that. ;D

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

nonnus29
Member #2,606
August 2002
avatar

:o 23yrold! :o

You shouldn't be working on this, you should be working on TMS!?!? ;D

Heh, well one of the first things you'll need for both items is a member table;

USERID
DATEJOINED
NUMBEROFPOSTS
PASSWORD
etc...

Haven't done this myself yet...

Thanks for the source kanzure, I'm gonna look it over see how you do things!

Edit:

Yep, but the idea with SQL is that your vectors (classes too!) will tables/child tables.

Kanzure
Member #3,669
July 2003
avatar

23: the translation is easy, with php4/5, since there are classes. But...remember, use the database! Php scripts are only ran when a browser calls them. But the classes each would be a table, the variables would be columns. Yep.

Edit: Hmm. You seem to have forgotten your unsigned char's for the names of the forums and posters ;) :P.

Richard Phipps
Member #1,632
November 2001
avatar

Unless it's almost done and he's working on the webpage?

Kanzure
Member #3,669
July 2003
avatar

Richardson: Doubtful. ::)

;D

Richard Phipps
Member #1,632
November 2001
avatar

Kanzureson: I can hope.
(Hey you sound Japanese!) ;)

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

Edit: Hmm. You seem to have forgotten your unsigned char's for the names of the forums and posters.

PHP does not support unsigned integers. ;)

I did lots of work on TMS this week, and will continue to do more today. That's the "other stuff" I mentioned. :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Kanzure
Member #3,669
July 2003
avatar

Quote:

(Hey you sound Japanese!)

Good job. Took you people long enough.

Edit:

Quote:

;)

Take that back. I was commenting to the C++! Php has simple variables.

$name = "Sir Bob Johnson Yeighen Heighmer Smith (the one that's my name too!), Senior, the Third"

Edit2:

Quote:

Sounds like a tekken fighter to me.

I went to a friendly japanese to english translation site, typed in a few words, and combined them. Can't remember any of them, but one of them was "hazure", and..uh..hmm.. Oh well. Supposadly, my name was a combination of words - "End of Perfection" (I was young, mind you. I was perfect, and still am :P ;)).

Richard Phipps
Member #1,632
November 2001
avatar

Oscar Giner
Member #2,207
April 2002
avatar

Quote:

Okay, I'm going to talk in C++ here. So I'd do something like this?

Problem about thinkin in c++ is that SQL is not OO. For example, in that post you said that a thread would have (among other things) a vector of posts, but that's not doable in SQL. I prefer thinking directly in tables. That's how it would look like:

1table cathegories
2 id (integer, primary key)
3 name (string)
4 
5table forums
6 id (integer, primary key)
7 cathegory (integer, foreign key to cathegories)
8 name (string)
9 
10table threads
11 id (integer, primary key)
12 topic (string)
13 forum (integer, foreign key to forums)
14 
15table posts
16 id (integer, primary key)
17 poster (integer, foreign key to members)
18 thread (integer, foreign key to threads)
19 time (datetime)
20 message (string)

MySQL doesn't support foreign keys, but I put them anyway to make things clearer.

This is the basic form. You can store some derived info in some tables to make things easier/faster. For example, in my forums, I store the number of posts of a thread in the thread table. This makes simpler to count the number of posts in a forum. I also found useful storing the post id of the last post of the thread. Just don't forget to update these ;)

Quote:

Sometimes I hear people talk about programs they use for adding news to their sites or something ... not sure if that's just my imagination ...

The news on my web page are stored in a database. I have a small admin page where I can add news.

BAF
Member #2,981
December 2002
avatar

why not have a look at the pixelate php? i wrote all that... that could teach you (except for the forums, i just hacked those to make it look somewhat decent)

Thomas Fjellstrom
Member #476
June 2000
avatar

23: the only thing Id add is that a post and a thread are virtually the same thing.

My forums are setup that way, so technically it can be a threaded style forum, but currently its just setup to do the allegro.cc style (I hear matthew has the same type setup, the "threads" can actually be real threads).

I also have sub forums, so each forum can have children forums to make things a bit cleaner.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Okay, I'm going to talk in C++ here. So I'd do something like this?

I would heavily advise one thing: stay away from OOP on the web with scripted languages.

The easiest way to get something done is to simply have a single PHP page represent a page as seen with a browser. It's not the most elegant of approaches, but it's super easy to work with.

In general, I build pages like:

  • include common header

  • include secondary headers that are useful for some pages, but not all

  • process user input via GET/POST, updating / deleting data from DB as needed

  • pull data from database for this page

  • included common HTML header (via PHP)

  • display HTML data specific to this page

  • include common HTML footer (via PHP)

The trouble with OOP and web scripts is that ultimately you end up having every class depend on every class and you end up having to include all your files for each page view. While, this is fine for desktop applications that are compiled, it's not good for the web. You should focus on keeping things straight-forward.

I find OOP most useful in PHP for utility classes. Things like general DB connecitivy, sending e-mails, etc. I do not find it very helpful for representing things like Members, Forums, etc.

Kanzure
Member #3,669
July 2003
avatar

Speaking of these forums, I suggest some people take the ideas used here. ML said once that he designed replies to be able to easily a new thread in itself, with a few clicks. That'd be a neat feature to add. :)

Matthew Leverton
Supreme Loser
January 1999
avatar

Yes, the posts/threads here are all in the same table. The initial post has a parent id of 0 and all other posts have a parent id of the initial post. To implement sub-threads, they would just have to have parent ids of secondary posts.

However, if you know you are not going to do a threaded board, I would have a "forum_thread" and a "forum_post" table, mostly for optimization.

nonnus29
Member #2,606
August 2002
avatar

So what is a session id and how does it work?

Kanzure
Member #3,669
July 2003
avatar

Are you talking to me?

edit: (I'm serious. You kind of have to use contexts, ;))

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

So what is a session id and how does it work?

The web is stateless, so there's no way to tell that a person requested a consecutive string of pages. The session id is simply a magic number that is sent back and forth between the client and server on every page view to keep track of who is who. After X time of no page loads, the magic number expires and the session is lost.

If it sounds like a hack, it's because it is. The entire WWW (and Internet as a whole...) is run on a bunch of disjointed poorly planned protocols and languages that sorta work together.

Thomas Fjellstrom
Member #476
June 2000
avatar

Just think, all the major internet protocols are based on Telnet! ;D (ftp, http, etc)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Krzysztof Kluczek
Member #4,191
January 2004
avatar

All major protocols are based on TCP/IP. Telnet is terminal protocol and AFAIK includes some escape codes to move cursor around and do other stuff which HTTP and FTP won't understand. ;)

Matthew: Have you implemented your sessions yourself? Is this system better than PHP 4 sessions? :)

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Matthew: Have you implemented your sessions yourself? Is this system better than PHP 4 sessions?

This is how the PHP sessions work, along with every other web language. I just use the native session handler.

 1   2   3 


Go to: