mpharo Posted May 5, 2007 Share Posted May 5, 2007 When someone clicks on it, I would just do an insert into posts_read, that way when they refresh the page or revisit the site it is already there, I wouldnt deal with that insert on error update....just keep it simple, do a check and if not there make it new else make it old. Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245793 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 Yeah, but thing is it will insert a new entry everytime the user clicks on the link or refreshes the page. Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245804 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 not if it is already marked as read... #start of new button $postid = $row['oid']; echo "<form name=\"goto_post\" method=\"post\" action=\"page.php\">" . "<input type=\"hidden\" name=\"postid\" value=\"$postid\">"; $select=mysql_query("SELECT * FROM posts_read WHERE username='$logged' AND postid='$postid' ") or die(mysql_error()); $count=mysql_num_rows($select); if ($count==0) { echo "Not Read" . "<input type=\"hidden\" name=\"postread\" value=\"not_read\">"; } else { echo "Post Read" . "<input type=\"hidden\" name=\"postread\" value=\"read\">"; } echo "<input type=\"submit\" value=\"View This Post\">" . "</form>"; #end of new button page.php If ($_POST[postread]=='not_read'){ $insert=mysql_query("INSERT INTO posts_read (blah blah blah) VALUES (blah blah blah) ") or die(mysql_error()); } $select=mysql_query("SELECT * FROM tbl_thread WHERE postid='$_POST[postid]' ") or die(mysql_error()); while ($sql=mysql_fetch_array($select)){ echo "Post Name: ". $sql[postname] . "Post Body: " . $sql[postbody] . blah blah blah } a simple if statement from a passed in variable determines if you do the insert or not, it will be a lot faster to do one simple if statement than to do a sql query then return it to php then a check then another query.... Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245817 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 Thing is, this is what I have so far: <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."\">$outtitle</a> "; #start of new button $postid = $row['oid']; $select=mysql_query("SELECT * FROM posts_read WHERE username='$logged' AND postid='$postid' ") or die(mysql_error()); $count=mysql_num_rows($select); if ($count==0) { echo "<img src=\"images/new.gif\">"; } else { echo ""; } #end of new button I will have to figure out how to make a button a link. Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245832 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 is : <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."\">$outtitle</a> "; what a person will click on to take them to that post? if so what does officeview.php look like? Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245841 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 Yeah, that is what they click on. Here is part of the office view: $update=mysql_query("insert into posts_read values ('".$oid."','".$logged."','1')") or die(mysql_error()); $resulto1 = mysql_query( "SELECT users.*, office.* ". "FROM users, office ". "WHERE users.id = office.omid and oid='$oid'") or die( "Unable to select database"); $wordnum = mysql_num_rows( $resulto1 ); while( $rowo1 = mysql_fetch_array( $resulto1 ) ) { $o1title = $rowo1["otitle"]; $o1omsg = $rowo1["omsg"]; $o1usr = $rowo1["firstpost"]; $o1muname = htmlentities($rowo1["fname"]); $o1date = $rowo1["odate"]; } ?> The $o1 outputs are then placed into a table, so it looks clean. Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245847 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 I assume that you have register global variables turned off? otherwise this code wont work....but in your link you would just add something like this.... <a class=\"forummain\" href=\"officeview.php?oid=$row['oid']&post_read=true\">$outtitle</a> "; then in your officeview.php page you would do: If ($post_read){ $insert=blah blah blah } But if you dont have register globals turned off or your running php4.1 or greater you need to use the $_GET[] function to reference any of the variables passed in the url... Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245868 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 Ok, I must be doing something wrong here: I have tried: <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."&post_read=true\"> and <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."&postread=true\"> and <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."&post_read=1\"> and <a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."&postread=1\"> with: if ($post_read){ $insert=mysql_query("insert into posts_read values ('".$oid."','".$logged."','1')") or die(mysql_error()); } and if ($postread){ $insert=mysql_query("insert into posts_read values ('".$oid."','".$logged."','1')") or die(mysql_error()); } Still inserting new entries. I have postread = 1 if read, not really sure if that matters Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245883 Share on other sites More sharing options...
marcus Posted May 5, 2007 Share Posted May 5, 2007 Just a suggestion, but why don't you just store it in a cookie or session? Make three cookies [or] sessions: uid (being the users unique id), topic (being the topic id), time_topicid (being just time()). Name the cookies/sessions after the topic id. Then just go to your forums, add something: if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){ echo "Read: "; }else { echo "Unread: "; } If the cookie/session doesn't exist while going to the topic just add it. Then check the time, if the last post on that topic is greater than the time the person went to it, update the cookie/session to the new time. Within the IF statment posted above, you can add $time = "SOME QUERY TO FIND THE LAST TIME POSTED ON THAT TOPIC"; if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){ echo "Unread: "; }else { echo "Read: "; } So basically the whole code would be: if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){ if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){ echo "Unread: "; }else { echo "Read: " } }else { echo "Unread :"; } NOTE: It may not work since I just thought of it now. EDIT: This could also save database space Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245889 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 with one or 2 posts a cookie or session would work, but if you had a cookie with every one that you clicked on to mark as read, your cookie would become enormous very quickly, in your link every time you click on it your passing the same thing over and over....you need to setup 2 links one for if it is read then another if it isnt.... Thing is, this is what I have so far: #start of new button $postid = $row['oid']; $select=mysql_query("SELECT * FROM posts_read WHERE username='$logged' AND postid='$postid' ") or die(mysql_error()); $count=mysql_num_rows($select); if ($count==0) { echo "<a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."&post_read=1\">$outtitle</a> "; echo "<img src=\"images/new.gif\">"; } else { echo "<a class=\"forummain\" href=\"officeview.php?oid=".$row['oid']."\">$outtitle</a> "; } #end of new button Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245899 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 lol....sure....lol Thanks mgallforever, it has taken me 2 weeks to get this far on this code, and thanks to mpharo I am beginning to make some progress. One of the reasons that I am not pushing towards sessions/cookies is that I honestly do not know how to code them. My script so far has been trial and error....allot of error for sure. Yeah, that database filling up could be a problem in then end, will cross that road when I come to it, I guess. I am a really big noob to php/mysql. I am on my 2nd real intense script, first one I am still writting and almost done, it was a pretty simple script for hosting with whm/cpanel. This one on the other hand is giving me headaches...lol Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245905 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 Another reason not to use cookies for something like this, is because most browsers have a max cookie size, once you reach a point it wont allow you to write to it anymore, this is because anyone could easily write a script that continues to loop and write values in acookie until you run out of disk space....not really harmful but a very big annoyance...the entires your going to have in a database like this are going to be relitavly small, I have a MySQL database with 2 million entries, the size is less than 5MB, it is all about how the data is stored, and these values are just simple text that take up hardly any space at all for a database....MySQL dosent have a limit for a DB size, but you can notice significant performance hits when your over the 10GB range....I havent done the tests, but there are a lot of good articles out there that do great testing on this stuff... Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245908 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 omg, omg....you might now see me but I am bowing mpharo, thank you so very much, you have just releaved allot of stress and allot of me beating my head off my keyboard for the last week trying to figure out how to get this to work. Again, thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245911 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 no problem, if you need anymore help you know where to get it, if this topic is solved please click the solved button at the bottom of the page...Glad I could help... Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245913 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 Spoke too soon. Just realized a problem, well not really a problem just tried something and it didn't work the way I was hoping...lol Is there a way for this: if ($count==0) to also be able to read postread=0 Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245915 Share on other sites More sharing options...
mpharo Posted May 5, 2007 Share Posted May 5, 2007 if ($count==0 AND $postread==0) of if your trying to take it from your query if ($count==0 AND $sql[postread]==0) you can also use OR instead of AND... but why? Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245916 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 I tried something with replies. So if somebody replies to the post it updates the posts_read table table to mark postread=0. I just thought about it, I could have just deleted all of the entries where postid=oid Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245917 Share on other sites More sharing options...
SkyRanger Posted May 5, 2007 Author Share Posted May 5, 2007 went with the delete, much easier to work with. Thanks again. Now I can finally resolve this post and never come back to it again....lol Quote Link to comment https://forums.phpfreaks.com/topic/50012-solved-figure-out-which-posts-has-been-read-and-not-read/page/2/#findComment-245919 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.