Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Funzione comment di un blog

    Codice PHP:
    function comment ($id){
            
            
    mysql_connect($this->server$this->db_user$this->db_pass);
            
    mysql_select_db($this->database);

            
    $query mysql_query("SELECT comment.id, comment.username, comment.comment , comment.postid , DATE_FORMAT(comment.date, '%d/%m/%y') AS timestamp, user.avatar FROM comment, user WHERE comment.postid='$id' ORDER BY comment.id DESC");

            while(
    $array mysql_fetch_array($query)){

                if(
    $array["avatar"] ===""){
                
                    
    $array["avatar"] = "http://p3e2.altervista.org/avatar.gif";
                    
                }
                
                echo (
    "<h2>$array[id] - $array[username] [i]$array[timestamp][/i]    <img src=\"$array[avatar]\" /></h2>$array[comment]
    "
    );

            }
        
        } 
    Con questa funzione ottengo lo stesso commento per due volte!!! Dove sbaglio???

  2. #2
    Codice PHP:
    SELECT comment.idcomment.usernamecomment.comment comment.postid DATE_FORMAT(comment.date'%d/%m/%y') AS timestampuser.avatar FROM commentuser WHERE comment.postid='$id' ORDER BY comment.id DESC 
    la tua query effettua a grandi linee la seguente ricerca, cerca i dati dentro comment che corrispondano ad un determinato id e poi tutti i dati della table user.
    questo avviene perche' non hai una chiave che unisce la table user con la table comment. Hai mandato al database un riferimento solo su comment e non su user quindi in parole povere ti pesca un dato su comment e tutti i dati su user.
    per risolvere il problema dovresti mettere una chiave su comment , ad esempio userid che corrisponde all'id di un utente su user table e trasformare la query in
    Codice PHP:
    SELECT comment.idcomment.usernamecomment.comment comment.postid DATE_FORMAT(comment.date'%d/%m/%y') AS timestampuser.avatar FROM commentuser WHERE comment.postid='$id' AND comment.userid user.id ORDER BY comment.id DESC 
    oppure usare una JOIN
    Zend Framework Italian Forum
    http://www.zfforum.it

  3. #3
    Capito l'errore, il problema è che non tutti gli user sono registrati quindi adesso mi ritrovo con solo i commenti di quelli registrati... idee???

  4. #4
    bhe praticamente un utente non registrato potrebbe corrispondere ad un utente uguale per tutti, cio'e' che abbia un valore id fisso, praticamente unregistred. questa potrebbe essere la soluzione al problema e' un po macchinosa, ma mi sembra funzionante
    Zend Framework Italian Forum
    http://www.zfforum.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.