PHPmotion.fr


Le forum français du youtube clone gratuit !

Page "Les plus discutés" plus fiable et rapide.

Suivez ces tutoriaux pour rémédier aux problèmes les plus souvent rencontrés.

Page "Les plus discutés" plus fiable et rapide.

Messagepar X-Rayden sur Mar Aoû 19, 2008 8:23 pm

J'oppère plusieur sites en phpmotion et avec beaucoup de commentaire négatif. je doit avouer que la page "Les plus discutés" a.k.a. "Les plus commentés" (Most Discussed) est franchement mal faite.

les résultats de cette page ne sont pas bon, il donne des mauvais résultats, par pages.

J'ai donc décider d'y remédier.

Premièrement, un avertissement : cette modification fera en sorte que les résultats dans la page "Vidéos -> les plus commentés" et dans la page d'acceuil dans la section "Les plus commentés" serons différents et EXCLUSIF, ce qui veux dire que seul les vidéos AYANT AU MOINS 1 COMMENTAIRE seront affiché.

donc voici les modifications :

Dans la page seemore.php
rechercher :
Code: Tout sélectionner
if ($which_one == "comments") {


Tout juste après il devrais y avoir ce code :
Code: Tout sélectionner
$pagination = pagination("SELECT * FROM videos WHERE approved='yes' AND public_private = 'public' ORDER BY indexer DESC",
        $limit);
    $set_limit = $pagination[0]['set_limit'];
    $total_pages = $pagination[0]['total_pages'];
    $current_page = $pagination[0]['current_page'];
    $total_records = $pagination[0]['total_records'];
    $next_page = $pagination[0]['next_page'];//use in html navigation (src)
    $prev_page = $pagination[0]['prev_page'];//use in html navigation (src)
    $nl = $pagination[0]['nl'];//use in html navigation: next>>
    $pl = $pagination[0]['pl'];//use in html navigation: <<previous

    $result_featured = array();
    $sql = "SELECT * FROM videos WHERE approved='yes' AND public_private = 'public' ORDER BY indexer DESC LIMIT $set_limit, $limit";
    $query = @mysql_query($sql);
    while ($result1 = @mysql_fetch_array($query)) {

        //get comments inforation
        $video_id = mysql_real_escape_string($result1['indexer']);
        $sql2 = "SELECT * FROM videocomments WHERE video_id = $video_id";
        $query2 = @mysql_query($sql2);
        $comments_number = @mysql_num_rows($query2);
        $comments_array = array('comments' => $comments_number);
        //get star rating
        $stars_array = stars_array($video_id);//call the stars function (results returned as array)
        //merge comments array
        $result2 = @array_merge($result1, $comments_array, $stars_array);
        $result_featured[] = $result2;
    }

    //sort the final array by order of number of comments
    function arr_keys_multisort($arr, $my_key, $sort_type) {

        foreach ($arr as $key => $row) {
            $arr_tmp[$key] = $row["$my_key"];

        }

        if ($sort_type == 'desc')
            @array_multisort($arr_tmp, SORT_DESC, $arr);
        else
            @array_multisort($arr_tmp, SORT_ASC, $arr);

        return $arr;
    }

    $result_featured = arr_keys_multisort($result_featured, 'comments', 'desc');


mettez le en commentaire ou débarassé vous en, c'est le code problématique. remplacez le par ce code :

Code: Tout sélectionner
$pagination = pagination("SELECT * FROM `videocomments` JOIN `videos` ON `videocomments`.`video_id` = `videos`.`indexer` JOIN `member_profile` ON `videos`.`user_id` = `member_profile`.`user_id`  WHERE `videos`.`approved` = 'yes' AND `videos`.`public_private` = 'public' GROUP BY `videocomments`.`video_id` ORDER BY COUNT(`videocomments`.`video_id`) DESC", $limit);
#print_r($pagination);
    $set_limit = $pagination[0]['set_limit'];
    $total_pages = $pagination[0]['total_pages'];
    $current_page = $pagination[0]['current_page'];
    $total_records = $pagination[0]['total_records'];
    $next_page = $pagination[0]['next_page'];//use in html navigation (src)
    $prev_page = $pagination[0]['prev_page'];//use in html navigation (src)
    $nl = $pagination[0]['nl'];//use in html navigation: next>>
    $pl = $pagination[0]['pl'];//use in html navigation: <<previous

    $result_featured = array();
    $sql = "SELECT * FROM `videocomments` JOIN `videos` ON `videocomments`.`video_id` = `videos`.`indexer` JOIN `member_profile` ON `videos`.`user_id` = `member_profile`.`user_id`  WHERE `videos`.`approved` = 'yes' AND `videos`.`public_private` = 'public' GROUP BY `videocomments`.`video_id` ORDER BY COUNT(`videocomments`.`video_id`) DESC LIMIT $set_limit, $limit";
    $query = @mysql_query($sql);
    while ($result1 = @mysql_fetch_array($query)) {

        //get comments inforation
        $video_id = mysql_real_escape_string($result1['indexer']);
        $stars_array = stars_array($video_id);//call the stars function (results returned as array)
        //merge comments array and video array
      $result2 = array_merge($result1, $stars_array);
        $result_featured[] = $result2;
    }


maintenant pour index_ajax.php (Sur votre page d'accueil)

rechercher :
Code: Tout sélectionner
if ($which_one == "comments") {


commentez-le ou débarassez-vous en et changez le pour :
Code: Tout sélectionner
    $sql = "SELECT * FROM videos WHERE approved='yes' AND public_private = 'public' ORDER BY indexer DESC LIMIT 10";
    $query = @mysql_query($sql);
    while ($result1 = mysql_fetch_array($query)) {

        #get comments inforation
        $video_id = mysql_real_escape_string($result1['indexer']);
        $sql2 = "SELECT * FROM videocomments WHERE video_id = $video_id";
        $query2 = @mysql_query($sql2);
        $comments_number = @mysql_num_rows($query2);
        $comments_array = array('comments' => $comments_number);
        #get video rating stars ---reusable -------------------------------------------------------------------------------
        $stars_array = array();
        $stars_array = stars_array($video_id);
        #merge comments array and video array
        $result2 = @array_merge($result1,$comments_array,$stars_array);
        $result_featured[] = $result2;
    }

    #sort the final array by order of number of comments
    function arr_keys_multisort($arr,$my_key,$sort_type) {

        foreach ($arr as $key => $row) {
            $arr_tmp[$key] = $row["$my_key"];

        }

        if ($sort_type == 'desc')
            @array_multisort($arr_tmp,SORT_DESC,$arr);
        else
            @array_multisort($arr_tmp,SORT_ASC,$arr);

        return $arr;
    }
    $result_featured = arr_keys_multisort($result_featured,'comments','desc');


and change it for this one :
Code: Tout sélectionner
   $sql = "SELECT * FROM `videocomments` JOIN `videos` ON `videocomments`.`video_id` = `videos`.`indexer` WHERE `videos`.`approved` = 'yes' AND `videos`.`public_private` = 'public' GROUP BY `videocomments`.`video_id` ORDER BY COUNT(`videocomments`.`video_id`) DESC LIMIT 10";
    $query = @mysql_query($sql);
    while ($result1 = @mysql_fetch_array($query)) {
        $stars_array = stars_array($video_id);
      $result2 = @array_merge($result1,$stars_array);
        $result_featured[] = $result2;
    }


Bon phpmotion!
X-Rayden
 
Messages: 8
Inscrit le: Mer Juil 16, 2008 10:17 pm
Localisation: Québec, Qc, Canada

Retourner vers Guides et Tutoriaux

Qui est en ligne ?

Utilisateurs parcourant actuellement ce forum : Aucun utilisateur inscrit et 1 invité

cron