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 4602012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:54:57+00:00 2026-05-21T23:54:57+00:00

Quick sum up: I have a facebook-like activity wall on the user profiles. There

  • 0

Quick sum up: I have a facebook-like activity wall on the user profiles. There are multiple “sorting” options to choose from. So if they want to only see, say, their own activity, they click “Your Activity”. That part works perfectly. I am adding a new piece to this puzzle, where they can also sort through certain types of activity such as: posts, comments, votes, etc.

What I am trying to get this to do is, if they have their activity already selected, and then they check the Posts and Responses checkboxes, it should display only their posts and responses.

I am using checkboxes so they can check/uncheck things at will and jquery ajax/php to call this. Here are the checkboxes:

<div class="activitySelector">
    <a href="" id="stalk" class="selectOrder">Following Activity</a> &bull; <a href="" id="user" class="selectOrder">Your Activity</a>
</div>
<input type="checkbox" class="sortOption" id="post" /><label for="post">Posts</label>
<input type="checkbox" class="sortOption" id="response" /><label for="response">Responses</label>

Here is the jQuery/ajax:

$('input[type=checkbox]').live("click", function(){

    $('input:checked').each(function(){
        var ID = $('.activitySelector .selected').attr("id");
        var optionID = $(this).attr("id");

        if (optionID) {
            $('ul.streamActivity').html('<img src="/images/ajax-loader.gif" class="loader" alt="" />');

            $.ajax({
                type: "POST",
                url: "/profile/sort_activity.php",
                data: "sort="+ID+"&option="+optionID+"&user=<?php echo $user; ?>",
                cache: false,
                success: function(html){
                    $("ul.streamActivity").html(html);
                }
            });
        }
    });
});

And finally the PHP (I am only showing the code that has to do with what I am talking about…I have no need to show the full query as it is working perfectly, I just want you to be able to get right to the headache :P): sort_activity.php

if ($sort == "user") {
    $checkActivity .= " WHERE a.name = '$user'";
    $activityNum .= " WHERE a.name = '$user'";

    if ($option == "post") {
        if ($option == "response") {
            $checkActivity .= " AND a.type = 'Post' AND (a.type = 'Comment' OR a.type = 'Advice')";
            $activityNum .= " AND a.type = 'Post' AND (a.type = 'Comment' OR a.type = 'Advice')";
        } else {
            $checkActivity .= " AND a.type = 'Post'";
            $activityNum .= " AND a.type = 'Post'";
        }
    } elseif ($option == "response") {
        if ($option == "post") {
            $checkActivity .= " AND a.type = 'Post' AND (a.type = 'Comment' OR a.type = 'Advice')";
            $activityNum .= " AND a.type = 'Post' AND (a.type = 'Comment' OR a.type = 'Advice')";
        } else {
            $checkActivity .= " AND (a.type = 'Comment' OR a.type = 'Advice')";
            $activityNum .= " AND (a.type = 'Comment' OR a.type = 'Advice')";
        }
    }
}

So, essentially what this needs to do is realize that “Your Activity” (user) was already selected, and then IF “Posts” AND “Responses” is chosen after that, then display only YOUR posts and responses. Right now, it only displays one or the other (if both “posts” and “responses” are selected it seems to display only your responses. Which is half-way there lol.)

I’ve thought of maybe setting cookies or such so it remembers what they have checked, but I’d like to stay away from that if at all possible.

Any help would be greatly appreciated as I am trying to do a re-launch with these cool new features 🙂

UPDATE:
Here is the foreach statement I’ve added. Echo is in there to see if it’s calling it properly, which it is. Checking on and off the boxes displays post/response/vote – it’s just not displaying any results whatsoever :/

I think I need to do something like, if there’s more than 1 option then change AND to OR so that it selects all of them…maybe? Can’t seem to get it to work properly though.

if (isset($options)) {
foreach ($options as $option) {
    echo $option .'<br />';
    if ($option['post']) {
        $checkActivity .= " AND a.type = 'Post'";
        $activityNum .= " AND a.type = 'Post'";
    }

    if ($option['response']) {
        $checkActivity .= " AND (a.type = 'Comment' OR a.type = 'Advice')";
        $activityNum .= " AND (a.type = 'Comment' OR a.type = 'Advice')";
    }

    if ($option['vote']) {
        $checkActivity .= " AND a.type = 'Vote'";
        $activityNum .= " AND a.type = 'Vote'";
    }
}
}
  • 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-21T23:54:58+00:00Added an answer on May 21, 2026 at 11:54 pm

    What’s happening, is that you’re not sending all the checked values to the server. Just change your click binding to this:

    $('input[type=checkbox]').live("click", function(){
        var options = []; //We'll send an array of options instead only one
        var ID = $('.activitySelector .selected').attr("id");
        $('input:checked').each(function(){        
            var optionID = $(this).attr("id");
            options.push("options[]="+optionID);
        });
        if (options.length) {
            $('ul.streamActivity').html('<img src="/images/ajax-loader.gif" class="loader" alt="" />');
    
            $.ajax({
                type: "POST",
                url: "/profile/sort_activity.php",
                data: "sort="+ID+"&options="+options.join("&")+"&user=<?php echo $user; ?>", //Here we're sending 'options'
                cache: false,
                success: function(html){
                    $("ul.streamActivity").html(html);
                }
            });
        }        
    });
    

    As you see, we’re sending all the checked ID’s (options) not only one.

    Server side:

    <?php
      $options = $_POST['options'];
      //Now $options is an array with all checked IDs
      foreach($options as $option)... //Do your stuff with $options. Everything else remains the same
    ?>
    

    Hope this helps. Cheers

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

Sidebar

Related Questions

I'm sure there is a quick and easy way to calculate the sum of
Is there a simple and quick way to use sum() with non-integer values? So
Quick sum up: I have a social website where users can follow/post/vote etc. I
Quick rookie question please. Suppose I have a javsacript object like so: var meh=[[cars,27],
I have a quick JavaScript question. I was wondering if there's a way to
Quick question. What do you think, I have a few sites that use a
Quick question: what is the compiler flag to allow g++ to spawn multiple instances
Quick one, but thought I'd ask. Is there a better way of getting the
Quick question. There is a legacy website (that is not under my control and
Is there a (roughly) SQL or XQuery-like language for querying JSON? I'm thinking of

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.