Answer the question
In order to leave comments, you need to log in
Tape sorting is all and my choice?
News feed, like VKontakte.
Purpose: Show (switch) news or those users who are subscribed or show all by switching method. How to do it right.
there are tables in the database : Feeds
id | entity_id (автор) | title | content | likes | comments и т.д
id_user | id_subscription
user_id | name | и т.д
function add_subscriber($userid, $type, $typeId)
{
if (!subscriber_exists($userid, $type, $typeId)) {
forget_cache("subscribers-" . $type . '-' . $typeId);
db()->query("INSERT INTO `subscribers`(user_id,type,type_id)VALUES('{$userid}','{$type}','{$typeId}')");
return true;
}
return false;
}
function get_subscribers($type, $typeId)
{
$cacheName = "subscribers-" . $type . '-' . $typeId;
if (cache_exists($cacheName)) {
return get_cache($cacheName);
} else {
$result = array();
$query = db()->query("SELECT user_id FROM `subscribers` WHERE `type_id`='{$typeId}' AND `type`='{$type}'");
if ($query and $query->num_rows > 0) {
while ($fetch = $query->fetch_assoc()) {
$result[] = $fetch['user_id'];
}
}
set_cacheForever($cacheName, $result);
return $result;
}
}
AND (
`user_id` IN (SELECT `following_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` = {$logged_user_id} AND `active` = '1')
OR `recipient_id` IN (SELECT `following_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` = {$logged_user_id} AND `active` = '1' )
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question