Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法获得我对max的期望结果(如)_Php_Mysql_Sql - Fatal编程技术网

Php 无法获得我对max的期望结果(如)

Php 无法获得我对max的期望结果(如),php,mysql,sql,Php,Mysql,Sql,我想要一个查询,用户可以在他的特定朋友的帖子上检索max like。 意味着一个查询可以计算出用户朋友帖子中的最大喜欢度并显示出来(6月12日,123+喜欢度,Ayan) 会话ID=17。 接受的朋友ID=14,15,16 数据库图像-> 正如我们在表中所看到的,用户14得到了最大喜欢(5喜欢) 用户15得到了3个喜欢 现在我的问题是 <?php include('config.php'); $resultlp = my

我想要一个查询,用户可以在他的特定朋友的帖子上检索max like。 意味着一个查询可以计算出用户朋友帖子中的最大喜欢度并显示出来(6月12日,123+喜欢度,Ayan)

会话ID=17。 接受的朋友ID=14,15,16

数据库图像->

正如我们在表中所看到的,用户14得到了最大喜欢(5喜欢) 用户15得到了3个喜欢

现在我的问题是

<?php
               include('config.php');           
        $resultlp = mysql_query("SELECT * FROM friends WHERE requested='".$_SESSION['SESS_MEMBER_ID'] ."' and status='accepted' ");
            while($row3 = mysql_fetch_array($resultlp))
                                  {                 
                                 $qwe=$row3['addedby']; //result to make an array of friends

        //second result (PROBLEM HERE)-->                       
$resultm = mysql_query("SELECT * FROM comment where  commentid ='$qwe' and like_count= (select max(like_count) from comment where  commentid ='$qwe') ");                
while($rowm1 = mysql_fetch_array($resultm))
        { 
$id=$rowm1['name'];
$lc=$rowm1['like_count'];
$result44 = mysql_query("SELECT * FROM members where id='$id'");
while($row44 = mysql_fetch_array($result44))
                    { 
        $namel=$row44['fname'];}

                }  }
                ?>
您可以尝试以下方法:

    $resultm = mysql_query("SELECT id,commentid,content,name,MAX(like_count) as max_likes FROM comment where commentid='$qwe' group by commentid ");
此查询将为$qwe=15提供id 64的结果行,为$qwe=14提供id 70的结果行,作为相应的max like_计数