Partage
  • Partager sur Facebook
  • Partager sur Twitter

système de commentaire, de vote...

je voudrais savoir comment procéder pour créer les différent système en question

    3 décembre 2006 à 9:52:49

    Bonjour a tous les zéro :p

    J'aurais besoin d'aide car je voudrais créer un système de vote à étoile , un système de commentaire qui s'affichera sur la même page que le jeux a commenter et un système qui compte le nombre de fois que le fichier a était télécharger.

    voici un ch'tit schéma:
    -menu_abandonware: comme l'indique son nom, il classe tout les jeux d'action(par exemple) dans un page, en donnant le minimum d'information sur le jeu( image réduite du jeu, titre, nombre de commentaire, la note qu'a obtenu le jeu par les vote d'utilisateur, le nombre de fois que le fichier a pu être télécharger et ce que j'appelle l'état du jeu: si le jeu est en téléchargement, si c'est une démo ou si il faut l'acheter)
    -abandonware: ce fichier affiche toute les infos du jeu, il devra afficher en bas de la page les différent commentaire, lavjoute de commentaire se fera via cette page aussi et aussi la note du jeu.

    et voila je peux pas expliquer plus se que je recherche, je signale que je suis un noobs en programation php

    Merci de m'indiquez comment je doit procéder poru arriver a ce résultat.

    [edit: j'ai trouver un sytème d'étoile qui marche en ajax. mais au lieu d'enregistré les vote dans un fichier je voudrais qu'il les enregistre dans la BDD, je vais méditer dessus et je tien au courant pour ce qui veulent)

    [re-edit:j'ai cercher masi j'ai pas trouver. je post les fichier du sytème de vote si quelqu'un peu m'indiquez coment on procéde sa serait simpas^^:
    fichier ajax.php
    <?php
            /**
             * Backend file to manage rating
             *
             */

           
            if($_GET['idName'] == 'id') {
                    // add the rating to the field/database
                    $fp = fopen('rating.txt', 'a') or die ("Le fichier <b>rating.txt</b> n'a pas pu être ouvert pour l'édition.");
                    fwrite($fp, ','.$_GET['id']) or die ("Les infos n'ont pas pu être enregistrer dans le fichier <b>rating.txt</b>.");
                    fclose($fp);
                   
                    // display the current(new) rating
                    $file = file_get_contents('rating.txt');
                    $filearray = explode(',', $file);
                    echo array_sum($filearray)/count($filearray);
            }
            elseif ($_GET['idName'] == 'newid') {
                    // add the rating to the field/database
                    $fp = fopen('rating2.txt', 'a') or die ("Le fichier <b>rating2.txt</b> n'a pas pu être ouvert pour l'édition.");
                    fwrite($fp, ','.$_GET['id']) or die ("Les infos n'ont pas pu être enregistrer dans le fichier <b>rating2.txt</b>.");
                    fclose($fp);
                   
                    // display the current(new) rating
                    $file = file_get_contents('rating2.txt');
                    $filearray = explode(',', $file);
                    echo array_sum($filearray)/count($filearray);
            }
            else {
                    echo "Erreur";
            }
           
    ?>

    fichier Ajax Rating Counter
    <?php
            /**
             * This class collects and displays the rsting in realtime WITHOUT refreshing the page
             *
             * @author Rochak Chauhan
             */

           
            class AjaxRatingCounter {
                   
                    var $numberOfStart = 10;
                    var $code = '';
                   
                    /**
                     * Contructor function
                     *
                     * @return object
                     */

                    function AjaxRatingCounter($displayHeading = true) {
                            if ($displayHeading === true) {
                                    $this->code = '<center> <h1>Ajax Rating Counter</h1></center>';
                            }
                    }              
                   
                    /**
                     * Fucntion to display stars
                     *
                     * @param int $rating
                     * @param string $idName
                     *
                     * @return string
                     */

                    function addStars($rating, $idName) {
                           
                            if (trim($rating) == '') {
                                    die("ERREUR : L'estimation ne peut pas être laissée blanche ");
                            }
                           
                            $rating = ceil($rating);
                           
                            $this->code .= '<script type="text/javascript" language="JavaScript">
                                                    displayStars('
    .$rating.', "'.$idName.'");
                                            </script>'
    ;
                           
                    }       
                   
                    /**
                     * function to display stars
                     */

                    function displayStars() {
                           
                            return $this->code;
                    }
            }
    ?>

    fichier javascript.js
    var http = createRequestObject();
    var displayRating = '';
    var currentId = '';

    function createRequestObject() {
        var ro;
        var browser = navigator.appName;
       
        if(browser == "Microsoft Internet Explorer"){
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else{
            ro = new XMLHttpRequest();
        }
        return ro;   
    }



    function updateRating(obj, rating) {
            var id = obj.title;
            var fullId = obj.id;
            var idName = fullId.substr(0, fullId.indexOf('_'));
            var totalRating = rating;
            currentId = idName;

        http.open('get', 'ajax.php?id='+id+'&idName='+idName);
        http.onreadystatechange = handleResponse;
        http.send(null);
    }

    function handleResponse() {
            if(http.readyState == 4){
            var response = http.responseText;
           
                    if (response == 'ERROR'){
                            alert("Désoler... Votre vote n'a pas pu être pris en compte.");
                    }
                    else {
                            alert("Merci d'avoir pris le temps de voter.");
                    }
           
            displayRating = response.substr(0, 4);
            document.getElementById(currentId+'_showrating').innerHTML = 'Rating: '+displayRating;
            totalRating = Math.ceil(response);   
            var obj = document.getElementById(currentId+'_'+totalRating);
            changeover(obj, totalRating);
                    displayStars(rating, currentId);
        }
    }

    function changeover(obj, rating) {
           
            var imageName = obj.src;
            var id = obj.title;
            var index = imageName.lastIndexOf('/');
            var filename = imageName.substring(index+1);
            var fullId = obj.id;
            var idName = fullId.substr(0, fullId.indexOf('_'));
            var totalRating = rating;

            for(i=0; i<id; i++) {
                    var num = i+1;
                   
                    if (num%2 == 0) {
                            document.getElementById(idName+'_'+num).src = 'star_selec.png';   
                    }
                    else {
                            document.getElementById(idName+'_'+num).src = 'star_selec.png';
                    }
            }

    }

    function changeout(obj, rating) {

            var imageName = obj.src;
            var id = obj.title;
            var index = imageName.lastIndexOf('/');
            var filename = imageName.substring(index+2);
            var fullId = obj.id;
            var idName = fullId.substr(0, fullId.indexOf('_'));
            var totalRating = rating;
           
            for(i=0; i<id; i++) {
                    var num = i+1;
                   
                    if (num%2 == 0) {
                            if(i < totalRating) {
                                    document.getElementById(idName+'_'+num).src = 'star_afich.png';   
                            }
                            else {
                                    document.getElementById(idName+'_'+num).src = 'star_vide.png';     
                            }
                    }
                    else {
                            if(i < totalRating) {
                                    document.getElementById(idName+'_'+num).src = 'star_afich.png';   
                            }
                            else {
                                    document.getElementById(idName+'_'+num).src = 'star_vide.png';     
                            }
                    }
            }
    }

    function displayStars(rating, idName) {

            document.write('<center>');
           
            for(i=0; i < 5; i++ ) {
                    if(i%2 ==0) {
                            if(i < rating) {
                                    document.write('<img src="star_afich.png" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
                            }
                            else {
                                    document.write('<img src="star_vide.png" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
                            }
                    }
                    else {
                            if(i < rating) {
                                    document.write('<img src="star_afich.png" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
                            }
                            else {
                                    document.write('<img src="star_vide.png" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
                            }
                    }
            }

            if (displayRating == '') {
                    document.write('<br /><div class="ratingText" id="'+idName+'_showrating" >'+displayRating+'</div>');
            }
            else {
                    document.write('<br /><div class="ratingText" id="'+idName+'_showrating" >'+totalRating+'</div>');
            }
            document.write('</center>');

    }

    et le fichier exemple.php que vous trouverais aussi içi: http://experience.gamer.free.fr/example.php
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Ajax Rating Counter</title>
           
                    <script src="javascript.js" type="text/javascript"></script>
                    <style type="text/css">

                    .ratingText {
                            font-family: verdana;
                            font-weight: bold;
                            font-size: 16px;
                            color: #FFFFFF;
                            background-color: #FF0000;
                            width: 135px;         
                    }
                    </style>
            </head>
    <body>
    <?php
            /**
             * Example file
             *
             */

           
            // file/ database to be accessed for rating of 'id'
            $file1 = file_get_contents('rating.txt');
            $filearray1 = explode(',', $file1);
            $rating1 = array_sum($filearray1)/count($filearray1);
           
           
            // file/ database to be accessed for rating of 'newid'
            $file2 = file_get_contents('rating2.txt');
            $filearray2 = explode(',', $file2);
            $rating2 = array_sum($filearray2)/count($filearray2);
           
           
            require_once('AjaxRatingCounter.inc.php');
            $ajaxRatingCounter  = new AjaxRatingCounter();

            $ajaxRatingCounter->addStars($rating1, 'id');
            $ajaxRatingCounter->addStars($rating2, 'newid');
            echo $ajaxRatingCounter->displayStars();
    ?>

    </body></html>

    • Partager sur Facebook
    • Partager sur Twitter

    système de commentaire, de vote...

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown