Jump to content

Creating a Recently Viewed article Index


terungwa
Go to solution Solved by 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

Edited by terungwa
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Edited by terungwa
Link to comment
Share on other sites

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