Cless Posted May 23, 2009 Share Posted May 23, 2009 Similar to a forum, I need an efficient way to check if a user has read a topic or has not read it. What would be the most efficient way to doing so? Quote Link to comment https://forums.phpfreaks.com/topic/159419-readunread/ Share on other sites More sharing options...
jackpf Posted May 23, 2009 Share Posted May 23, 2009 Is this short term or long term? If it's the former, you could just save the ID's in a session. If the latter, you'd have to have a table for storing usernames and topic ID's. Then query the database to see if the username and ID exist, if so, the user has read the topic. That's hwo I'd do it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/159419-readunread/#findComment-840944 Share on other sites More sharing options...
Cless Posted May 23, 2009 Author Share Posted May 23, 2009 It is long term. I have also thought about doing sessions, but those would be short term. I was also thinking of storing it like that, I am worried, however, that this could cause some MySQL lag. I almost have 100,000 users. Quote Link to comment https://forums.phpfreaks.com/topic/159419-readunread/#findComment-840947 Share on other sites More sharing options...
RussellReal Posted May 24, 2009 Share Posted May 24, 2009 it shouldn't cause any lag, pull the data like you'd usually do.. and then assuming in the field the ids would be seperated by commas, e.g. 1,17,23,30,20,10 if (in_array($this_user_id,explode(',',$row['viewed_by_id']))) { // user has viewed this topic } Quote Link to comment https://forums.phpfreaks.com/topic/159419-readunread/#findComment-840951 Share on other sites More sharing options...
Cless Posted May 24, 2009 Author Share Posted May 24, 2009 Ah yes, I've never thought of doing it in an array form. I'll try it out. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/159419-readunread/#findComment-840952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.