Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4260628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:56:45+00:00 2026-05-21T05:56:45+00:00

Quick sum up: I have a social website where users can follow/post/vote etc. I

  • 0

Quick sum up: I have a social website where users can follow/post/vote etc. I am adding a new facebook-like activity wall feature to each users profiles.

I have worked on this bit for a few days now and can’t seem to get it to work properly. What I want is, well, exactly like the facebook wall as I mentioned…When a visitor visits a user’s profile, that user’s activity will display, whether they recently “voted” on a post, commented, or posted something of their own, I would like it to display on their profile and of course, have the most recent entries on top.

The problems I am having right now are: it’s displaying some things twice and it’s not sorting them by the most recent.

I am working with 3 tables here (I only posted the columns that I am using):

Table structure for table votes_posts
Field   Type    Null    Default
indexer int(11) No  
post_id int(11) No  
vote    int(11) No  
user_name   varchar(250)    No  
date    varchar(255)    No  

Table structure for table posts
Field   Type    Null    Default
id  int(11) No  
name    varchar(30) No  
content text    No  
datetimerss varchar(255)    No  
category    int(11) No  

Table structure for table comments
Field   Type    Null    Default
id  int(12) No  
post_id int(12) No  
name    varchar(30) No  
content text    No  
type    varchar(30) No  
datetimerss varchar(255)    No

$users is just $_GET[‘user’]
The timeAgo() function, simply displays the very popular “posted xx ago” date time.

<ul class="streamActivity">
<?php
$checkActivity = "SELECT votes_posts.post_id, votes_posts.user_name, votes_posts.vote, votes_posts.date, 
                        posts.id, posts.content, posts.name, posts.datetimerss, categories.category, 
                        comments.post_id AS comm_postid, comments.content AS comm_content, comments.name AS comm_name, comments.datetimerss AS comm_date, comments.type 
                        FROM `votes_posts` 
                        LEFT OUTER JOIN `posts` ON votes_posts.post_id = posts.id 
                        LEFT OUTER JOIN `comments` ON posts.id = comments.post_id 
                        LEFT OUTER JOIN `categories` ON posts.category = categories.cat_id  
                        WHERE (votes_posts.post_id = posts.id AND user_name = '$user')
                        OR (comments.post_id = posts.id AND comments.name = '$user')
                        OR (posts.name = '$user') ORDER BY votes_posts.date, posts.datetimerss, comments.datetimerss ASC";
$checkActivityResult = mysql_query($checkActivity);

if (mysql_num_rows($checkActivityResult) > 0) {
    while ($sessionAct = mysql_fetch_array($checkActivityResult)) {
        $category = strtolower($sessionAct['category']);
        $dateVote = timeAgo($sessionAct['date']);
        $datePost = timeAgo($sessionAct['datetimerss']);
        $dateComm = timeAgo($sessionAct['comm_date']);

        $namePost = $sessionAct['name'];
        $nameComm = $sessionAct['comm_name'];
        $nameVote = $sessionAct['user_name'];

        $idVote = $sessionAct['post_id'];
        $idPost = $sessionAct['id'];
        $idComm = $sessionAct['comm_postid'];

        $contentPost = $sessionAct['content'];
        $contentComm = $sessionAct['comm_content'];
        $typeComm = $sessionAct['type'];

        if ($namePost == $user) {
            $classList = 'storyPost';
            $classIcon = 'iconMuttr';

            $name = $namePost;
            $content = $contentPost .' ... read more';
            $datetime = $datePost;
        }

        elseif ($nameComm == $user && $typeComm == "Comment") {
            $classList = 'actionPost';
            $classIcon = 'iconComment';

            $name = $nameComm;
            $content = 'Commented "'. $contentComm .'"';
            $datetime = $dateComm;
        } elseif ($nameComm == $user && $typeComm == "Advice") {
            $classList = 'actionPost';
            $classIcon = 'iconAdvice';

            $name = $nameComm;
            $content = 'gave Advice "'. $contentComm .'"';
            $datetime = $dateComm;
        }

        elseif ($nameVote == $user) {
            if ($sessionAct['vote'] == "1") {
                $classList = 'actionPost';
                $classIcon = 'iconLaughed';

                $name = $nameVote;
                $content = 'Laughed at "'. $contentPost .'"';
                $datetime = $dateVote;
            } elseif ($sessionAct['vote'] == "2") {
                $classList = 'actionPost';
                $classIcon = 'iconLoved';

                $name = $nameVote;
                $content = 'Showed Love on "'. $contentPost .'"';
                $datetime = $dateVote;
            } elseif ($sessionAct['vote'] == "3") {
                $classList = 'actionPost';
                $classIcon = 'iconIdiot';

                $name = $nameVote;
                $content = 'called '. $namePost .' an Idiot for "'. $contentPost .'"';
                $datetime = $dateVote;
            }
        }
?>
    <li class="row-activity <?php echo $classList; ?>">
        <a href="" class="avatar"><img src="/images/avatars/default_male.jpg" /></a>
        <div class="info">
            <div class="userName">
                <a href=""><?php echo $name; ?></a>
            </div>
            <span class="msgBody"><?php echo $content; ?></span>
            <div class="imgTimeStream">
                <span class="img <?php echo $classIcon; ?>"></span>
                <span class="source"><?php echo $datetime; ?></span>
            </div>
        </div>
    </li>
<?php
    }
} else {
    echo '<p>This user has no recent activity.</p>';
}
?>
</ul>

I am by no means an expert programmer…everything I know I have pretty much taught myself over the past year or two, so I can only imagine how ugly this truly is lol. I am learning each and everyday though, and I hope to continue 🙂

Also, within each type of activity, there will be slightly different CSS classes on some things.
Example:
if the result row is a post then the css class of the list item would be “post”
if the result row is a vote then the css class of the list item would be “vote”
etc.

Any help would be appreciated!

UPDATE: Well multiple Queries seemed to work fine…no more duplicates. I even have it only displaying the last couple of months of activity (for now anyway). Now I need to figure out how to mix the results, so the most recent one’s (whether it’s a vote or post, etc.) be at the top.

P.S. I probably should mention that A LOT of data will be passing through this (think of a facebook wall+twitter feeds lol)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:56:46+00:00Added an answer on May 21, 2026 at 5:56 am

    You should turn your query into a union of 3 statements (votes, posts, comments) that return the same set of columns. What’s happening in your query is that multiple votes, posts or comments are multiplying out the rows generated by the query.

    As an aside, you should convert to using parametrized SQL if possible, to eliminate potential SQL injection vulnerabilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick rookie question please. Suppose I have a javsacript object like so: var meh=[[cars,27],
Quick question: if I have an XML like this one: <?xml version=1.0 encoding=utf-8?> <cop
Quick question, I have the following string which is a coma separated list of
Quick sanity check - I wanted to create a new remote branch for myself.
Quick method description: I have two tables, lets name them table ONE and table
Quick question (and sorry if it's already been asked, I have looked but couldn't
Have a quick JS question. What is the difference between math.round and parseInt? I
In short I have 2 tables: USERS: ------------------------ UserID | Name ------------------------ 0 a
I'm sure there is a quick and easy way to calculate the sum of
Quick question. I have a fortran77 subroutine with a variable declaration DIMENSIONS HH(13, 1000)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.