Jump to content

Creating a Recently Viewed article Index


terungwa

Recommended Posts

I am creating a recently viewed article index for my PHP/MYSQL forum script that will store recently viewed articles  that a user may have forgoten to bookmark.  This way the Web site will be able to remember which articles they read and present a list.

To remember which documents have been read by a given user, i am identifying each user and each document by a unique identifier.For the user, the session ID satisfies this requirement.

 

I have got the script working but the viewed list is not incrementing, rather a new viewed article always overwrites the old one.

What i want to create is a list of all articles read.

 

My code is below:

topic.php

session_start()
// database connection
//Extract articles from database for display on the topics page
$_SESSION['post']=array(); //create an array to hold read articles
// Add article title and link to list
$PostLink = "<a href='topic.php?topic={$topic}'>{$topic}</a>";
if (! in_array($PostLink, $_SESSION['post'])){
$_SESSION['post'][] = $PostLink;}
// Output list of requested articles this bit of code is to be place in the sidebar
if(isset($_SESSION['post'])){
echo "<p>Recently Viewed Articles</p>";
echo "<ul>";
foreach($_SESSION['post'] as $doc) {
echo "<li>$doc</li>";
 }
echo "</ul>";}

Any thoughts on how i may achieve this

Why don't you add the Article ID and the User ID into a specific table within the database; this method would be efficient, and would never expire unless the user could remove recently viewed articles. Seems much more efficient and will probably be more secure...

 

Kind regards,

Jason Moore

X5HOST.co.uk

Why don't you add the Article ID and the User ID into a specific table within the database; this method would be efficient, and would never expire unless the user could remove recently viewed articles. Seems much more efficient and will probably be more secure...

 

Kind regards,

Jason Moore

X5HOST.co.uk

Thanks Jason.

Even though I have resolved the problem, I shall take a look at your proposal.

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.