Jump to content

Recommended Posts

Hi all I'm trying to get a news feed I have got the news feed working although the results are in order of each user then in order of timestamp, I am tryng to just order by the timestamp.

 

I also realize that it is because of running two queries, If you can make up a new query feel free I'm shit with mysql :(

 

Please help.

$friends = $database->query("SELECT `person_id` FROM `friends` 
WHERE `friend_id` = 'Admin' 
AND `status` = 'Active'
UNION SELECT `friend_id` FROM `friends` 
WHERE `person_id` = 'Admin' 
AND `status` = 'Active'");
$i = 0;
while($f = mysql_fetch_array($friends)){
	if($f['friend_id'] != $session->username or $f['person_id'] != $session->username){
		 if($av != "true") { $visible =  " AND `visibility` = 'true' "; }
		 $posts = $database->query("
		 SELECT * FROM `status` 
		 WHERE `person_id` = (
		 	SELECT `person_id` FROM `friends` 
			WHERE `friend_id` = 'Admin' 
			AND `status` = 'Active' 
			UNION SELECT `friend_id` FROM `friends` 
			WHERE `person_id` = 'Admin' 
			AND `status` = 'Active' 
			LIMIT ".$i.", 1) 
		OR `friend_id` = (
			SELECT `person_id` FROM `friends` 
			WHERE `friend_id` = 'Admin' 
			AND `status` = 'Active' 
			UNION SELECT `friend_id` FROM 
			`friends` WHERE `person_id` = 'Admin' 
			AND `status` = 'Active' 
			LIMIT ".$i.", 1) ORDER BY `timestamp` DESC");
		 $i++;
			while($p = mysql_fetch_array($posts)) { 
				if($p['post_type'] == "status"){ 
					include("status.php"); 
				}elseif($p['post_type'] == "photo") { 
					include("photos.php");	
				} 
			} 	
	}
}
Link to comment
https://forums.phpfreaks.com/topic/277728-getting-news-feed/
Share on other sites

Yes but I don't know how use them properly I have tried but the results are too unpredictable as I need to check names "friends against statuses" with 4 possible combinations first:

 

"status" person = "friend" person

"status" friend = "friend" person

"status" person = "friend" friend

"status" friend = "friend" friend

 

then get statuses without repeating posts

 

the closest I have come is

SELECT `status`.*, `friends`.`person_id`, `friends`.`friend_id`
FROM `status`, `friends`
WHERE 
(
	`friends`.`person_id` = 'Admin' 
	AND `friends`.`person_id` = `status`.`friend_id`
)
OR
(
	`friends`.`friend_id` = 'Admin' 
	AND `friends`.`friend_id` = `status`.`friend_id`
)
OR
(
	`friends`.`friend_id` = 'Admin' 
	AND `friends`.`friend_id` = `status`.`person_id`
)
OR
(
	`friends`.`person_id` = 'Admin' 
	AND `friends`.`friend_id` = `status`.`person_id`
)

GROUP BY `status`.`id`
ORDER BY `status`.`timestamp` DESC 
Link to comment
https://forums.phpfreaks.com/topic/277728-getting-news-feed/#findComment-1428745
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.