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.
我试图这样做的是,如果他们的活动已经选定,那么他们就应当只显示自己的职位和对策。
我正在使用检查箱,以便他们能够按意愿检查/检查物品,并打断一个jax/php。 这里是检查箱:
<div class="activitySelector">
<a href="" id="stalk" class="selectOrder">Following Activity</a> • <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>
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);
}
});
}
});
});
最后,PHP(我只想表明与我所谈论的内容有关的法典......) 我无需表示完全的问候,因为它正在完美地工作,我只想让你能够接触到头脑:P:平常。
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 )";
}
}
}
因此,基本上需要做的是认识到,已经选定了“Your activity”(用户),然后选择了“Posts”和“Responses”,然后只显示YOUR职位和答复。 现在,它只是显示一种或另一种(如果选择“职位”和“责任”似乎只是你的答复。 半途
我怀念也许会建立厨师,这样我会记得他们已经检查过什么,但我想尽可能避免。
如果我试图用这些冷却的新特征重新发射,将非常感激任何帮助:
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 :/
我认为,如果有一个以上选择,那么我就需要做些什么,这样它就可以选择所有选择。 似乎无法让它妥善工作。
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 ";
}
}
}