Page 1 of 1

Help with a forum

Posted: Tue Jun 25, 2002 4:14 am
by Data
I am attempting to make a forum using PHP and mySQL.
At the moment it is working - you can add posts properly.

However I want the name of the poster to become a link to a page with info about them, and would like to reference the users by ID, rather than name if possible.

I loop through the posts with a while statement:

Code: Select all

while ($myrow = mysql_fetch_array( $threadresult )) 
		{
		printf("<tr><td>%s</td><td>Posted by: %s</td></tr><tr><td colspan="2">%s</td></tr>\n", $myrow&#1111;"post_no"], $myrow&#1111;"poster"], $myrow&#1111;"message"]);
	
		&#125;
The users info are in another table.
How can I get it so that instead of the name of the poster, there will be a link to the info page, referenced by the id of the poster?

Is this possible? or should I just the the name of the poster?

Posted: Tue Jun 25, 2002 5:21 pm
by Mahmoud
select table1.whatever, table1.whatever2, table2.userinfo from table1, table2 where ...

Posted: Tue Jun 25, 2002 5:23 pm
by Mahmoud
Why do not you just download a free php board and choose it ?

there is InvisionBoard which is very fast and comes with a lot of features.
and also you can try phpbb : http://www.phpbb.com

Posted: Wed Jun 26, 2002 3:22 am
by Data
I don't want to use a ready made board - I want to try and make something for myself.

Can you explain more about what you posted?

Posted: Wed Jun 26, 2002 6:47 am
by jason
Data: You an ex C coder? Dont' use printf() here....

Anyways.

Code: Select all

while ($myrow = mysql_fetch_array( $threadresult )) 
     &#123; 
          echo "<tr><td>".$myrow&#1111;"post_no"]."</td><td>Posted by: <a href="pagetoUserStuff.php?userID=".$myrow&#1111;'userid']."">">$myrow&#1111;"poster"]."</a></td></tr><tr><td colspan="2">".$myrow&#1111;"message"]."</td></tr>\n"; 
     &#125;
Something like that should work fine

Posted: Wed Jun 26, 2002 9:02 am
by Data
No, PHP is the first programming I have done.
And this would be the second actual working project I have tried.

How would the above work though? The userID is in a different table than the rest of the forum.

Maybe I will just use the names - it seems to be a lot simpler.

Posted: Wed Jun 26, 2002 5:53 pm
by Mahmoud
you can select information from more than one table.
The query should look like

Select table1.column1, table1.column2, table2.column1 from table1, table2
where ...


ex.
tables: users and posts
describe users;
id, username
describe posts;
id, post, whatever, uid
// you will store in the uid the user id

Code: Select all

SELECT u.id AS userid, u.username AS username, p.post AS post, p.whatever AS whatever
FROM users as u, posts as p
WHERE u.id = p.uid and p.id = $_GET&#1111;postid];
I assume in this code that you request the post using the postid through GET request method

this query will generate
userid | username | post | whatever |
ex.
$myrow["userid"] that's the userid
$myrow["username"] that's the username
$myrow["post"] that's the post
$myrow["whatever"] that's whatever ..

- remember to use htmlspecialchars($_POST[post]);
to disable the html codes ..

Posted: Thu Jun 27, 2002 5:34 am
by Data
Thanks anyway but I found another way to do it, which is almost the same.

I just didn't have the sql syntax correct for taking info from two tables.

It works now anyway!

Posted: Thu Jun 27, 2002 5:44 am
by twigletmac
Why don't you post your solution to help anybody else who's looking for the same info...

Mac

Posted: Thu Jun 27, 2002 1:25 pm
by Data
Ok, here is the sql I used:

SELECT * FROM forum,users where forum.boardid = $boardid and forum.threadid = $threadid and forum.poster=users.name

It is the "forum.poster=users.name" that is the important part - it connects both the tables together through a common name.