• User Attivo

    [PHP] OOP - Ritorno di array di stringhe + smarty

    Ciao,
    devo estrarre i commenti che gli utenti hanno mandati in merito ad una certa domanda/testo.
    Per farlo utilizzo il metodo $answers->grab($id);
    [PHP]class answers{

    function grab($qid){ //Stampa tutte le risposte di una certa domanda

            $result = $this->query("SELECT * FROM answers WHERE qid='$qid'");
            
            
    
            while ($row = mysql_fetch_array($result)) {
                        
                        
                        $this->row['user_id'];
                        $this->row['text'];
                }
    

    }

    }[/PHP]
    Ora però non so come estrarre i dati da questo metodo. Perchè se faccio:
    $answers->row['user_id'] ottengo solamente l'ultimo record del database. Come faccio ad ottenerli tutti insieme.

    Poi dovrei stamparli con smarty. Ma una volta che sono riuscito a farlo con il metodo, smarty non è un problema.

    Quello che vorrei è che se faccessi foreach($answers as $answer){

    echo $answer->text;
    echo $answer->user_id;

    }

    insomma un array che contiene a sua volta gli array con il testo e l'user_id. Non so' se è l'array multidimensionale, ma non so' come strutturarlo?

    grazie mille


  • Bannato User Attivo

    non capisco il codice che hai riportato ma sono appena sveglio e ci stà...
    in ogni caso se voi mettere le row in un array answers di row basta che nel while assegni answers[]=$row;
    così facendo dopo il tuo foreach su answers dovrebbe funzionare.