0

我在一些页面中最喜欢的前 10 名(不要问为什么,这只是我网站中从我的数据库提供的链接的一个选项)

我现在正在这样做,所以我可以从链接中看到所有链接和 facebook 喜欢的数量。现在我想进入前十,但不知道如何?我是否需要将它们全部存储,在数组中使用新的 if 语句,然后显示它。

你们会如何处理这件事?

PHP:

function get_the_fb_like($paginaurl){

        $url = $paginaurl; // setting a value in $url variable

        $params = 'select comment_count, share_count, like_count from link_stat where url = "'.$url.'"'; // preparing the query for the url

        $component = urlencode( $params ); // prepare the url for fetching the information from facebook

        $url = 'http://graph.facebook.com/fql?q='.$component; // constructed url

        $fbLIkeAndSahre = json_decode( file_get_contents_curl( $url ) ); // convert the json from our response to object

        $getFbStatus = $fbLIkeAndSahre->data['0'];

        return $getFbStatus->like_count; // return the number of like of the passed url

    }

    $result = $pdo->prepare('SELECT * FROM photos where geupload = :maandenjaar AND goedgekeurd = :goed');

    $result->execute(array(':maandenjaar' => $maandenjaar, ':goed' => 'ja'));

    $numrows = $result->rowCount();

    if($numrows != 0){
        foreach ($result as $row) {

            if(get_the_fb_like('?photo='.$row['id'].'') != 0){
                echo '
                            <div class="imgwrap">
                                <a href="'.$row['id'].'" title="'.$row['caption'].'"><img src="'.$row['location'].'" alt="'.$row['beschrijving'].'" /></a><br />
                                <p>Likes: '.get_the_fb_like('?photo='.$row['id'].'').'</p>
                            </div>
                        ';
            }

        }   
    }else{
        echo 'Er zijn geen afbeeldingen deze maand';
    }

编辑:

你们不是很明白我的问题,对不起。我会试着解释一下。我有一个带有图片 ID 的数据库。那个人可以喜欢。

对于点赞数,我使用 facebook api by url 来获取 url 的点赞数。所以我无法从我的数据库中限制 10 个,因为我没有将计数存储在我的数据库中。

4

2 回答 2

0

尝试

$params = 'select comment_count, share_count, like_count from link_stat where url = "'.$url.'" ORDER BY like_count desc LIMIT 10'; // preparing the query for the url
于 2013-09-02T18:32:16.537 回答
0

假设您的所有链接都存储在link_stat表中,看起来就像您的问题的情况,您可以对表进行排序查询并返回前 10 个结果。

SELECT *
FROM link_stat
ORDER BY like_count
LIMIT 0, 10
于 2013-09-02T18:30:39.737 回答