It's time to learn me stuff
23yrold3yrold

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.

Kanzure

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

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

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

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

nonnus29

: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

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

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

Kanzure

Richardson: Doubtful. ::)

;D

Richard Phipps

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

23yrold3yrold
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. :)

Kanzure
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

Sounds like a tekken fighter to me. :)

Oscar Giner
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

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

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.

Matthew Leverton
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

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

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

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

Kanzure

Are you talking to me?

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

Matthew Leverton
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

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

Krzysztof Kluczek

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
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.

Thomas Fjellstrom
Quote:

All major protocols are based on TCP/IP.

They are implemented on TCP/IP.

Quote:

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.

AFAIK those escape codes aren't really apart of telnet its self, just the terminal you're running on (vt100, xterm, something). Just look at HTTP, NNTP, POP3 and friends, they are so simplistic, some text headers and maybe some content.

Krzysztof Kluczek
Quote:

They are implemented on TCP/IP.

That's what I meant.

Quote:

AFAIK those escape codes aren't really apart of telnet its self, just the terminal you're running on (vt100, xterm, something). Just look at HTTP, NNTP, POP3 and friends, they are so simplistic, some text headers and maybe some content.

In this case almost everything is based on telnet. ;)

Thomas Fjellstrom

Most of them are :)

X-G
Thomas Fjellstrom

Ok.. Lets just say the Telnet as I know it ;) (anything equivelent to raw mode in putty ;D)

Krzysztof Kluczek

MS Telnet has control codes too. ;)

Anyway, doesn't it sound strange to say that Quake 3 net code is based on telnet? (If HTTP was based on telnet and supports binary transmission, anything could be said to be based on telnet) ;)

X-G

Quote:

anything equivelent to raw mode in putty

Raw mode is exactly that. A raw TCP/IP connection. Not telnet. :P

Thomas Fjellstrom

Does the quake3 protocol look anything like:

Client:
GET /uri HTTP/1.0
Header1: foo
Header2: bar

Possible data here.

Server:
200 OK HTTP/1.0
Header1: foo
Header2: blah

data here

?

edit:
and in the "binary" sense, its just data. look at a request/response pair for any file:

GET /index.html HTTP/1.0

200 OK HTTP/1.0
Content-Type: text/html
Content-Length: 1024

data here for 1024 bytes.

yay. Theres alot more to http, but thats the basics.

X-G

Uhm, that's HTTP you're describing. Zorro didn't say anything about Q3 being based on HTTP...

Thomas Fjellstrom

He said it was based on Telnet, Which I argue most of the limited antiquated common protocols are based on. I know HTTP, the others, not so much.

elver

Tomasu, X-G informs me that you think HTTP is based on Telnet. Please stop believing that as it's not true. Thank you.

Uhh... I need sleep. Exam in two hours! Bloody hell... >:(

Krzysztof Kluczek

TF: I completely agree that many net protocols are text-based, but telnet isn't one of them despite of looking like one. :)

Matthew said:

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.

Doesn't it require too many database searches when displaying posts? It seems that it requires one query per post. Or are there other fields which accelerate searching?

X-G

SELECT * FROM forum_posts WHERE parent='foo';

One query. Returns all posts in a thread.

Krzysztof Kluczek

Heh, I misunderstood it. I though they were linked in a list, which would require much more effort to access them. :)

Thomas Fjellstrom

Only if you want to show an entire thread, if its threaded, instead of just listed like it is here.

X-G

Perhaps one could have a system where every post stores not only its immediate parent, but every parent in its thread; so that a few levels down, for instance, a post could have a "parents" field like "1;15;24;27" or similar. It would take up a bit of space, but probably be faster than doing several queries to show an entire thread.

Matthew Leverton

I store three ids:

post_id, parent_id, root_id

(In my case parent_id and root_id are always identical. )

Such a structure allows you to get all the threads in one query in the proper order if you grab associatively by [SORT BY parent_id, post_id] and can make the assumption that higher post id = later time.

What you would do then is:

0 Grab Data from DB into $parents[0] = first post, $parents[$thread_id] = array of base posts, $parents[$post_id_X] = array of sub threads
A Show first post
B For Each $parents[$thread_id]
C-- If $parents[$post_id] exists (sub thread), go to B
D End For Each

This only works though if you grab from the base of the thread. Ie, if you want to grab a specific sub thread, you are out of luck.

If you wanted to do it with any thread, I'd probably create a lookup table like:

1
+-2
| +-3
|
+-4

post_id | parent_id | direct_flag
---------------------------------
 1      | 0         | 1
 2      | 1         | 1
 3      | 1         | 0
 3      | 2         | 1
 4      | 1         | 1
---------------------------------

You could do things like

SELECT FROM post WHERE post_id IN (SELECT post_id FROM parent_link WHERE parent_id = $X AND direct_flag=1)

That would give you all direct replies. Eliminate the direct_flag, if you want to get the entire list of children, and you could use the above mentioned method for looping through them without having to do a db query for each sub thread (ouch).

23yrold3yrold

Any advice on how to set up my system as an Apache server so I can test PHP/MySQL here? I found this, but it looks excessively painful. :( Or is that the standard procedure? No download-this-file-and-double-click-it method? :)

Kanzure

Quote:

download-this-file-and-double-click-it method?

Sourceforge - search for "PHP Triad for Windows".

ReyBrujo

You using Windows? Download the latest Apache executable (I tried with the 1.3x something, the 2.x had something broken) and install it. Then install and configure MySQL. Finally, download PHP, put the module in the Apache directory, and edit httpd.conf to process PHP pages with PHP before showing them. That is basically what I did a year ago and worked quite fine :)

Oscar Giner
Quote:

download-this-file-and-double-click-it method?

EasyPHP

23yrold3yrold

Why is it in French? >:(

I'm going to try Kanzure's suggestion. If that doesn't work, I'm going to try ReyBrujo's suggestion. If that doesn't work, I'm going to say "screw comoputers" and go move to Tibet and be a monk.

Quote:

Sourceforge - search for "PHP Triad for Windows".

Google turned up the SourceForge page easier than SourceForge did. ^_^ Not much info on this thing, is there ...

Mars

Check out some WAMP solution. WAMP is LAMP with Windows instead of Linux. :)

23yrold3yrold

PHP Triad seems to be working. I haven't figured out how to make it load my pages yet ... it really seems to like c:\apache\htdocs. ;D ::)

Kanzure

Quote:

I haven't figured out how to make it load my pages yet

What?? That addy you gave is right for your files.. what's teh problem?

23yrold3yrold

Yeah, but that's annoying. :) Why can't I just double-click my .php file to open it? ;)

Anyway, yeah. My PHP scripts are working now, albeit only from the one directory. Time to formally try MySQL ...

ReyBrujo

You defined your DocumentRoot variables?

23yrold3yrold

My who what?

X-G

Your Apache configuration (httpd.conf). Look for a line that says "DocumentRoot". Change it. Restart Apache.

23yrold3yrold

I only get the one directory? Bah! :)

I'll play with that ...

ReyBrujo

Yep :) You can declare aliases later, so that accessing http://127.0.0.1/games/index.html access in fact /DOCUMENTROOT/PAGES/GAMES, etc.

Kanzure

Quote:

Yeah, but that's annoying. Why can't I just double-click my .php file to open it?

Well, you can associate notepad with it or something to edit it. And, if you want to just click on it, and have it popup the parsed page, you could make it a link to http://localhost/thefile.php...Because php.exe parses the php files when apache says so, and opening the file would have no call to php.exe (and also no way of enviorement variables! :o)

Somebody can probably offer a better explanation ;)

23yrold3yrold

I know; I figured that much out on my own. :)

ReyBrujo

Maybe you can setup your text editor to call for php.exe before opening it. Or maybe you can even create a bat file with something like

php.exe %1 > %TEMP%\temp.html
iexplore %TEMP\temp.html

and add it to your Send To menu (code not tested!!!).

Jakub Wasilewski

Rey: I believe SciTE does something like that implicitly for PHP files, when you use the "Go" command from the menu. Not sure if 23 is using SciTE, though ;).

Thomas Fjellstrom

23: apache also lets you create aliases to any file/folder on your computer, or heck, you can redirect a file/folder to an external address. Or you can create Virtual Hosts, and have more than just "localhost" work, you can have "my1337game" and/or "23yrold3yrold.com" point at the same or different document roots. :) Then theres user pages, you remember that ~ (tilde) thing you see alot? You can do that too! once enabled, Apache on XP defaults http://localhost/~USER/ to <b>C:\Documents and Settings\USER\My Documents\My Webpage</b> or something similar. which of course, you can change. :D

Apache is really nice, if a bit bloated.

23yrold3yrold

This thread again? :P

Yes, I use SciTE. :)

Thread #369331. Printed from Allegro.cc