FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Custom Forums





garionw
I am in the process of creating custom forums to help integrate with my site better. I've come is the entire "new posts" thing. I originally started this conversation over at Whirlpool, but decided to start it over here as well for a more mixed response.

Does anyone know how I can have topics (and forums) display another icon if there was a new post? and how it changes back to normal if you've already read the topic.

| - New Post (Read)
| - New Post
| - New Post
| Old Post
| Old Post
| - Locked Topic

in that example above, the dashes represent the "New Topics", but seeing as though I've already read the top one, I don't need a dash there

Thanks in advance,
Garion
ncwdavid
I would use a cookie id say. That would be the best way I could think of but I am sure there is lots of other ways too and they may be easier or harder.
X3 Talk
I guess that this is the way PHPBB does it. When you look at a post, it puts an entry with your name into a database. It also stores a timestamp.

Then, when it gets that post, it looks when it was last modified and compares this to the timestamp from the database.

Hope that time makes sense.
kv
ncwdavid wrote:
I would use a cookie id say. That would be the best way I could think of but I am sure there is lots of other ways too and they may be easier or harder.


cookies are local to a browser. If you use some other browser/other profile on the same machine/some other machine, this information is not available.

Database entry is the best solution. Once a topic is read, add an entry in a table for that user against the topic id (or whatever is the key).
garionw
kv wrote:
ncwdavid wrote:
I would use a cookie id say. That would be the best way I could think of but I am sure there is lots of other ways too and they may be easier or harder.


cookies are local to a browser. If you use some other browser/other profile on the same machine/some other machine, this information is not available.

Database entry is the best solution. Once a topic is read, add an entry in a table for that user against the topic id (or whatever is the key).


That'd be one pretty big table wouldn't it? and also a large number of query's per second if there were ten or so users online?
qscomputing
If you have a table to store user sessions, store the articles that have been read by a particular session, then delete those rows when the session expires.

Any article that hasn't been modified since the last visit has been read. Any article listed under the user's session has been read. All other articles are unread.

HTH.
sonam
I am sugest to use array (sessions or not). You need only one array with all informations per user.
was read - normal state (TRUE)
new - something new (FALSE)
When your user come insert all new post in array.
$forum1 = array(2345, 6789);
$forum2 = array(980920,0320,0024975980920,0320,0024975);
// ... etc forums arrays

$user = array(fourm1,forum2); // user array

Then read with if or with something better (I haven't other idea in this moment) Shocked
Code:
if($user[fourm1] == "") {
   $image = forum_was_read.jpg
} else {
   $image = forum_new_post.jpg
}



Do the same thing with post and when user open some post unset this number from array. When user leave your forum array can stay for next time and you can fill it with new informations on next login.

Sonam
garionw
sonam wrote:
I am sugest to use array (sessions or not). You need only one array with all informations per user.


Thats a great idea, do you mind if I use it, and I might use a cookie, so it won't cause too many mySQL queries, and it can remember your "unwatched" topics when you close the window.

The only thing I can think of now, is, getting the new topics after the cookie has been set. I say that because, if you stay really need a reply to your topic, you would probably stay and keep refreshing the forum for updates.

I can't set the variable on each page load, because that would destroy the purpose of marking them read, but I could have two cookies, one with the topics that are new, and one with the ones that are read? (These would probably expire after 48 hours or so

That would work wouldn't it?? Rolling Eyes Rolling Eyes
kv
I can't help but repeat this. If you rely on cookies, it works only for that browser and that machine. It doesn't work if the same user switches browser or machine.

Using database will make a big table, but it can be optimised. Time taken for querying the table will be very less compared to the time taken for getting the page. User will hardly notice any change.
sonam
Quote:
remember your "unwatched" topics when you close the window


If you want remember unwatched topics then you must use some type of data base (cookie, MySql, Flat File (txt file)) and you need some queries. That is reason why KV talking about diference between cookie and MySql.

Quote:
so it won't cause too many mySQL queries


Only if you don't want unwathded topics then you can store only last visit time in your DB and you need only one querie. On next visit fill session array with all unread topic and reset DB on new time. All topic stored in session array will show new_image.jpg and other will show read_image.jpg. When user leave your forum (close browser) PHP will destroy session.

Sonam
garionw
Just one other question.

At present, the topic information has a table to itself (Containing Signature, Title....) and more importantly whether its a sticky.

Is it possible to display rows which have a certain value above others while in a single mysql query, because I don't want to have too many per page.
umairpk85
very nice....... keep going
garionw
garionw wrote:
Just one other question.

At present, the topic information has a table to itself (Containing Signature, Title....) and more importantly whether its a sticky.

Is it possible to display rows which have a certain value above others while in a single mysql query, because I don't want to have too many per page.


Is anyone able to help please? I can do two ORDER BY statements (ORDER BY type, lastpost DESC) but it still orders by the lastpost and not the type
kv
garionw wrote:


Is anyone able to help please? I can do two ORDER BY statements (ORDER BY type, lastpost DESC) but it still orders by the lastpost and not the type


That is a bit strange. Are you sure type is the first parameter for order by? If not, make it the first parameter and try. Also, what is the data type of "type"?
garionw
Ok, Here are the results from the different arrangements Wink

Select * FROM topics ORDER BY topic_type, topic_date DESC
Code:
+----------+------------+------------+
| topic id | topic type | topic date |
+----------+------------+------------+
|   20     | normal     | 13/03/01   |
+----------+------------+------------+
|   18     | sticky     | 13/03/07   |
+----------+------------+------------+
|   21     | sticky     | 13/03/02   |
+----------+------------+------------+

This looks the most promising, its just getting the "types" right. what values can I try and how are they measured. Its an ENUM, BTW with two options normal (first) and sticky (second)

Select * FROM topics ORDER BY topic_date, topic_type DESC
Code:
+----------+------------+------------+
| topic id | topic type | topic date |
+----------+------------+------------+
|   20     | normal     | 13/03/01   |
+----------+------------+------------+
|   21     | sticky     | 13/03/02   |
+----------+------------+------------+
|   18     | sticky     | 13/03/07   |
+----------+------------+------------+


Select * FROM topics ORDER BY topic_date DESC
Code:
+----------+------------+------------+
| topic id | topic type | topic date |
+----------+------------+------------+
|   18     | sticky     | 13/03/07   |
+----------+------------+------------+
|   21     | sticky     | 13/03/02   |
+----------+------------+------------+
|   20     | normal     | 13/03/01   |
+----------+------------+------------+


Select * FROM topics ORDER BY topic_type DESC
Code:
+----------+------------+------------+
| topic id | topic type | topic date |
+----------+------------+------------+
|   18     | sticky     | 13/03/07   |
+----------+------------+------------+
|   21     | sticky     | 13/03/02   |
+----------+------------+------------+
|   20     | normal     | 13/03/01   |
+----------+------------+------------+
Related topics
New forums?
ShoutBox in Forums!
Custom error pages using .htaccess
Mark all forums read
THE FORUMS!
Your FOrums
Other Forums
Interview: Derek Liu, Gaia Online Anime Community
forums
Custom Sigs/Avatars(Static or Animated) 6frih$ each
Check out Defection Design Studios
Defection Design Studios
SuExec, source compile? Custom Doc_Root?
IPB custom pages ?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.