The row titled "accessed" starts out with "0" and grows by 1 each time a unique or different reader opens the article.
I need some ideas as to how I should setup the database table to do this.
I'll have tables:
- submit_article_users - rows: s_user_id, s_user_name, etc.
- articles - rows: article_id, s_user_id, accessed, title, content
- read_article_users - rows: r_user_id, r_user_name
- track - rows: article_id, r_user_id
[PHP]<?php
$article_id' = $_GET['article_id''];
$query = "SELECT * FROM articles WHERE article_id = '$article_id'";
$result = mysql_query ($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$title = stripslashes($row['title']);
$article_id = $row["article_id"];
$s_user_name = stripslashes($row['s_user_name']);
$s_user_id = $row["s_user_id"];
}
echo "<strong>$title</strong> by $s_user_name<br><br>$content";
// Check if article has been opened before by reader.
$query = "SELECT r_user_id FROM track
WHERE r_user_id = '".$_SESSION['r_user_id']."'
AND article_id = '$article_id'";
$result = mysql_query ($query);
if ($result) { // Reader has accessed this article before so do nothing.
Should I put this here or leave this area blank?
include ('includes/bottom.php'); // Include the footer.
exit();
}
else
{
// The reader has not accessed this article before so add '".$_SESSION['r_user_id']."' and $article_id to table track and increase $accessed by 1 in the articles table.
// I'll need help with how to do this
$query = "INSERT into tract VALUES ('$article_id', '".$_SESSION['r_user_id']."');
$result = mysql_query ($query);
$accessed = ($accessed + 1);
$query = "UPDATE articles SET accessed='$accessed' WHERE article_id = $article_id";
$result = mysql_query ($query);
}
include('includes/bottom.php'); // Include the footer.
?>[/PHP]
I have not tried this code yet because I know that it would fail. I would like to know if what I have here would come anywhere close to doing what I need it to do? Any help woud be appreciated.
Thanks.
David