Jump to content

[SOLVED] Figure out which posts has been read and not read


SkyRanger

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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