开发者

How to check if receive new response on the posts that user responsed before?

开发者 https://www.devze.com 2023-03-11 11:07 出处:网络
Let\'s say there are 10 posts, and I have sent a response onto 7 of posts. When other user send response to the posts, the system must check and tell me if a开发者_如何学运维ny 7 of posts receive a ne

Let's say there are 10 posts, and I have sent a response onto 7 of posts. When other user send response to the posts, the system must check and tell me if a开发者_如何学运维ny 7 of posts receive a new response. The system will not check the other 3 posts, it will check the 7 posts that I have responded only.

Step 1 - SELECT post-id FROM responsesLive WHERE username='{$myUsername}'; //This will output many duplicated post-id if I sent multiple responses onto a particular post. How to prevent the duplicated post-id?

Step 2 - After I get 7 of the post-id, I need to get the response-id of last response in each of the 7 posts. Do I need to use array to store the 7 post-id? Or I just need to write this query within while loop of previous query like :

$query3 = "SELECT id FROM responseslive WHERE username='{$myUsername}'";
$result3 = mysql_query($query3,$connection) or die (mysql_error());
confirm_query($result3); 
while($postinfo = mysql_fetch_array($result3)){
    $post-id= $postinfo['post-id'];

    $query4 = "SELECT rsp-id FROM responseslive WHERE postid='{$post-id}' ORDER BY rsp-id DESC LIMIT 1";
    $result4 = mysql_query($query4,$connection) or die (mysql_error());
    confirm_query($result3); 
    while($rspinfo = mysql_fetch_array($result4)){
        $last-rsp-id= $rspinfo['rsp-id'];
    }

}

Step 3 - Then compare current $last-post-id to previous $last-post-id, if current $last-post-id is greater than previous $last-post-id, then tell the user that there is a new response on the post that he have responded before.


For step 1:

SELECT DISTINCT post-id FROM responsesLive WHERE username='{$myUsername}';

this will returns only distinct post-ids.

For step 2:

SELECT 
  postid, max(rsp-id) 
FROM 
  responseslive 
WHERE postid in (
    SELECT DISTINCT post-id FROM responsesLive WHERE username='{$myUsername}');
GROUP BY
  postid

This will give you and array with posts ids and their last responses ids.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号