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

    [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);
    Codice 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'];
                    }
    }


    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

  2. #2
    Codice PHP:
    class answers
        function 
    grab($qid){ //Stampa tutte le risposte di una certa domanda 
            
    $result $this->query("SELECT * FROM answers WHERE qid='$qid'"); 
            
    $tmp= array();
            while (
    $rowmysql_fetch_object($result)) { 
                
    $tmp[]= $row;                 
            } 
            
    mysql_free_result($result);
            return 
    $tmp;
        } 




    PS.
    Identa il codice.
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    ok, ora xò non riesco a stamparlo con smarty. come fare?

  4. #4
    Originariamente inviato da leonapster
    ok, ora xò non riesco a stamparlo con smarty. come fare?
    Non uso smarty


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.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 © 2025 vBulletin Solutions, Inc. All rights reserved.