Jump to content

[SOLVED] making a forums by hand...and i need help


L

Recommended Posts

Hey,

I decided to make a forums from scratch...it's been going well so far...but now i am stuck on the whole new/hot/old threads idea...

For example: I'm trying to make what these forums have at the bottom of the page...then news posts icon, u posted here icon, and the other icons that show under specific conditions...

I'm dumbfounded with this concept as I have no idea what to do concerning this...would i have another column in `threads` named `level`?

then in an include on every page put update rank to x is conditions for x is true? but then have that  for z, y, w, v, u as well as the conditions make it that specific variable?

i'm sorry if this is confusing, but I'm stumped and I need help...

 

Basically I'm trying to make the whole (show new post icon if new post) and (show no new posts icon if no new posts) thing. What defines a new and an old post..and how could i possibly define those? That was another problem i was encountering...so if anyone can help me, please do.

 

Thank you for your time

~L

ok...maybe i dont get this because I'm getting confused...if I store the date of a post in my db i will have x. But then when I check x with time()(using this to insert into database) for only that minute will the message be new....after that minute it'll be considered old....how do i make it so each user has their own perspective of new and old....

or am I getting all of this wrong and do forums just do it the way you specified... ??? ???

um...can u be more specific....if ur sayin' i need a users table and membership that's all already been set up....i just want to know how to place a new posts icon near a thread with a new post....the trouble is i don't know how i can define what's new or not....ur method suggests,in my opinion, that a thread will have new posts if the time of the latest post is equal to the current time now....but how can i make it so if the latest post if more than 1 day old it is considered old?

 

I think that's the answer!...but would i compare the post time to

time()-x = $nw

what should x be

 

Thank you for all your help....I think I got it!

~L

You'll need a table that has a many-to-many relationship that shows if the user has viewed the post or not.

 

Post_table User_table

| |

| |

  Post_user_map_table

 

  Fields

 

  Post-id User-id

 

Run the SELECT query (discussed later) to see whats new and whats not. If a user clicks a thread that is new run an INSERT query with their user_id and the post_id and insert a record to the post_user_map_table.

 

To set viewed posts run a SELECT query and if a user_id and post_id match are retrieved then the user already viewed the post and adjust the threads look to illustrate that. Follow?

interesting...when a user clicks the thread 'Hello' their time, session['id'], and the id of the thread will be inputed into the Post_user_map_table

 

a user posts in the thread....it will now show a (newimage) image next to it, IF the time record where userid=session['id'] in the Post_user_map_table is < the time of the post ?? ???

 

If so I'll be happy  ;D!!...if not ill be dumbfounded and back to the start :(

 

sorry for my inability to not easily grasp this...once a method is stuck in my head it's hard to edit it...thanx for all your help thus far

~L

New to the user will need a seperate table for logged on times. That inputs the time that the user last viewed the forum. For example...

 

Last_login_table

 

fields

 

user_id

last_login_time

 

Script that executes... (place at the top of every page.)

 

<?php

// I used mysql's built in NOW() function for simplicity I prefer PHP's time().

IF (issest($_SESSION['user_id'])) {
    $query = "UPDATE last_login_table SET last_login_time= NOW()";
    $result = mysql_query($query)or die(mysql_error());

}

 

Now you will need to run a query to check when the user returns to see what threads were posted after their last login time. So you will need to adjust your login script to set a session variable to $_SESSION['last_login']. Then run a query finding thread id numbers that were posted after that time. follow?

I'm also working on displaying a 'new' icon on my forum project.

Please note I am new and this is probably wrong. :)

 

I did it a bit different though...

 

I'm working off the "last post" msg id of a topic to see if it's new or not.

 

I made a table 'sbb_log_topics'.

This table gets inserted 3 values:

- user_id (I insert the $_SESSION['user_id'] that I made at login)

- topic_id (the id of the topic)

- msg_id (the last post message id)

 

I insert those values when a user views a message.

 

Then when he views the topics page, I check to see if the values match with the "last post" msg id on that page. If they match he doesn't get a 'new' icon.

 

Here are the functions I am using:

 

			// Get the last msg id from a topic
		function get_last_post($topic_id){

				$sql="SELECT MAX(msg_id) AS lastpost FROM sbb_posts WHERE topic_id='$topic_id'";
				$sqlresult=mysql_query($sql) or die(mysql_error());
				$result=mysql_fetch_row($sqlresult);
				return($result);
		}

		// Add the msg id a seen
		function log_topic($userid, $topic_id, $last_post_id) {								

				// Check if we added it or not 
				$sql = "SELECT * FROM sbb_log_topics WHERE user_id='$userid' AND topic_id='$topic_id' AND msg_id='$last_post_id'";
				$sqlresult = mysql_query($sql) or die(mysql_error());	
				$result=mysql_num_rows($sqlresult);
					if ($result < 1){			
				// We didn't add it, then let's add it... 
				$sql1 = "INSERT INTO sbb_log_topics (user_id, topic_id, msg_id) VALUES('$userid', '$topic_id', '$last_post_id')";
				$result1 = mysql_query($sql1) or die(mysql_error());	
				}					
		}

		// Check to see if the user has seen the last posted messsage
		function check_topic($userid, $topic_id, $last_post_id) {

				$sql = "SELECT * FROM sbb_log_topics 
						WHERE 
						topic_id='$topic_id' AND
						user_id='$userid' AND
						msg_id='$last_post_id'";
				$sqlresult=mysql_query($sql) or die(mysql_error());
				$result=mysql_num_rows($sqlresult);
				return($result);
		}

 

To display the new icon I do this:

 

	
		// Get the last msg id
		$topic_id = $topic['topic_id'];
		$lastpost = get_last_post($topic_id);
		$last_post = $lastpost[0];

if ($logged_in){	
	// get the last post
	$last_post_id = $last_post;
	// log topic seen vars
	$topic_id = $topic['topic_id'];
	$userid = $_SESSION['user_id'];

$checktopic = check_topic($userid, $topic_id, $last_post_id);
if ($checktopic < 1){ echo'<span class="smalltext"><strong>new</strong></span>';

	} 
}

 

And on my messages page I use this to add the values when a user views the message:

 

		// log topic seen vars
	$topic_id = $post['topic_id'];
	$userid = $_SESSION['user_id'];
	// Get the last post
	$lastpost = get_last_post($topic_id);
	$last_post = $lastpost[0];
	// add the msg as seen
	log_topic($userid, $topic_id, $last_post); 

 

It's seems to be working for now. :)

Like I said I am new so this might not be the best way to do it.

The problem I can see is that the "sbb_log_topics" table will get very big.

 

hmm...yah...i think im gona skip that part then, lol...but since i don't want to spam up the forums ill place my other question here that has to do with my forums that im building

 

basically i want to display who posted the last post, at what time, and in what thread on my index for the forums...

So I have a Last Post column...what should come is this

'hello'

by 'L'

at time

so i set up two fetches

$latest = mysql_query("SELECT `threadid`,`by`,`date` FROM `posts` WHERE `topsid`='".$p['id']."' ORDER by `date` desc limit 1") or die(mysql_error());
$lastest = mysql_fetch_array($latest);
$name = mysql_fetch_array(mysql_query("SELECT `name` FROM `threads` WHERE `id`='".$lastest['threadid']."'", $conn1)) or die(mysql_error());

 

but when i upload it nothing appears...but not only that..everything on the page under those queries don't appear...i'm not sure what i'm doing wrong and help is much appreciated...the only thing i can find is that when i don't include the "WHERE `topsid`='".$p['id']."'" in the query it just shows me the details of the last post...but just the last post in general...i want the last post for each category

 

Thank you for your time

~L

 

 

EDIT: nm...it turns out that if there are no posts in the query pretty much dies..so i gotta add an invisible post :)

Hey,

I am back to the icon changing this...but now I got it to partially work...The icon changes if it's a sticky, if i posted in it, and if its hot....

Now the problem is with the new and the old...this is what i have

//two queries
$postimeme = mysql_fetch_array(mysql_query("SELECT `timestamp` FROM `post_user_map_table` WHERE `id`='".$_SESSION['userid']."' and `threadid`='".$threads['id']."'", $conn1));
$postime = mysql_fetch_array(mysql_query("SELECT `timestamp` FROM `posts` WHERE `threadid`='".$threads['id']."'", $conn1));

if ($numposts >= 16 && $postimeme['timestamp'] > $postime['timestamp']) {
echo "<img src=\"images/hotold.gif\" alt=\"threadpic\" />";
}
if ($numposts >= 16 && $postimeme['timestamp'] < $postime['timestamp']) {
echo "<img src=\"images/hotnew.gif\" alt=\"threadpic\" />";
}
if ($postimeme['timestamp'] < $postime['timestamp'] && $by <= 0 &&  $numposts < 16) {
echo "<img src=\"images/new.gif\" alt=\"threadpic\" />";
}
if ($postimeme['timestamp'] > $postime['timestamp']) {
echo "<img src=\"images/old.gif\" alt=\"threadpic\" />";
}

 

i want the old hot and the old gifs to show if the time the user viewed the thread($postimeme['timestamp']) is more recent than the time of the post($postime[timestamp'])

The new icons show...but the old ones don't show after I click the thread...which means that a new timestamp should be updated in the post_user_map_table so the thread can be shown as old....can anyone tell me what I'm doing wrong?

 

Thank you for your time

~L

  • 2 months later...

Well I noticed I didn't mark this topic solved...so why not post in this, right?

 

I want to display when the most amount of people were once online, and then display who is online

I checked out my tables and it all checks out..the only thing left is the code...is my code wrong in any way?

 

$ghj = mysql_query("SELECT * FROM `most_users`", $conn) or die(mysql_error());
$most = mysql_fetch_array($ghj);

echo "Most users ever online was ".$most['number'].", ".$most['date'].".<br />";
$qa = mysql_query("SELECT `username` FROM `users` WHERE `online`='1'", $conn);
while ($online = @mysql_fetch_array($qa)) {
echo "<a href=\"/memberscript/account.php?user=".$online['username']."\">".$online['username'].", </a>";
}

 

Thank you

haha...i guess i really didn't state that did I?...no it's not working...and I'm getting this warning

 

faultCode0faultStringWarning:mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vol2/prohosts.org/ph_1001118/taizku.prohosts.org/htdocs/forums/index.php on line 74

 

on line 74 is

while ($online = mysql_fetch_array($qa)) {

I read up on it and I placed a @ in front of the "mysql_fetch_array", but when I did that no warning, nor anything showed....

 

EDIT: Sorry wrong stuff...now it's good, :)

Archived

This topic is now archived and is closed to further replies.

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