Visualizzazione dei risultati da 1 a 9 su 9

Discussione: funzione sconosciuta

  1. #1

    funzione sconosciuta

    Ciao a tutti,
    ho una classe con una porzione di codice così:

    Codice PHP:
    function estrapolaUltimoCommento($IDATTIVITA,$stampa){
            
    $this->queryUltimoCommento="SELECT idUTENTE, Nick, WebSite, Email, TitoloCommento, Commento, DataCommento, Bpubblicato FROM tblCOMMENTI WHERE idATTIVITA=".$this->IDATTIVITA." ORDER BY DataCommento DESC";
            
    $this->eseguoUltimoCommento mysql_query($this->queryUltimoCommento,$this->db) or die ("Errore nella query Ultimo Commento: ".mysql_errno()." Descrizione: ".mysql_error());
                
    //SE STAMPO E' 1 STAMPO I COMMENTO
                    
    if($this->stampa==1){
                            while(
    $this->ultimoCommento mysql_fetch_array($this->eseguoUltimoCommento)){
                            
                            echo
    "
                            <p class=\"commenti_ajax\">
                            <img src=\"img/avatar.gif\" class=\"avatar\" />
                            <span class=\"titolo_commenti\">"
    .$this->ultimoCommento[TitoloCommento]."</span>

                            <span class=\"corpo_commenti\">"
    .$this->ultimoCommento[Commento]."</span>

                            <span class=\"coda_commenti\">Rilasciato da 
    $ultimoCommento[Link] il [i]$ultimoCommento[GiornoCommento] alle ore $ultimoCommento[OraCommento][/i]</span>
                            </p>
                            "
    ;
                            }
                    } 
    Se io però provo ad utilizzare nella funzione estrapolaUltimoCommento() un funzione che dichiaro subito dopo nella classe (elaboraUltimoCommento()) mi restituisce l'errore call to funzione sconosciuta...

    Eppure la funzione c'è, anche se la sposto prima nel codice...

    Sapete dirmi perchè?

  2. #2
    Se è un metodo di una classe, devi richiamarlo tramite $this->estrapolaUltimoCommento() oppure con l'operatore :: (in caso di chiamata statica).

  3. #3
    Eppure se la dichiaro così:

    Codice PHP:
    while($this->ultimoCommento $this->elaboraUltimoCommento(mysql_fetch_array($this->eseguoUltimoCommento))) 
    in apertura di pagina l'applicazione non risponde...

  4. #4
    Non è che hai introdotto un Parse Error nel codice?

  5. #5

  6. #6

  7. #7
    Codice PHP:
    <?php
         
    class Estrapola{
        public 
    $IDATTIVITA;
        public 
    $percorso_foto;
        public 
    $row;
        public 
    $ultimoCommento;
        public 
    $stampa;
        private 
    $db;
        private 
    $select_db;
        private 
    $eseguo;
        private 
    $eseguoUltimoCommento;
        private 
    $query;
        private 
    $queryUltimoCommento;
        private 
    $close;
        
            function 
    __construct(){
            
    $this->db_host="localhost"
            
    $this->db_user="user"
            
    $this->db_password="pw"
            
    $this->db_name="database";     
            }
            
            function 
    connetti(){
            
    $this->db mysql_connect($this->db_host$this->db_user$this->db_password) or die ("Errore nella connessione al database numero: ".mysql_errno()." Descrizione: ".mysql_error());
            
    $this->select_db mysql_select_db($this->db_name$this->db) or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
            }
            
            function 
    disconnetti(){
            
    $this->close=mysql_close($this->db);
            }
            
            function 
    estraiRecord($IDATTIVITA) {
            
    $this->query="SELECT AT.IDATTIVITA, AT.NomeAttivita, AT.DescrizioneAttivita, AT.IndirizzoAttivita, AT.TelefonoAttivita, AT.LatitudineAttivita, AT.LongitudineAttivita, AT.ComeArrivare, AT.VotoCriterio1, AT.VotoCriterio2, AT.VotoCriterio3, AT.VotoCriterio4, AT.EMangiare, AT.EBere, AT.EFumare, AT.EDisabili, AT.EParcheggio, AT.ECani, AT.ECondizionata, AT.ECarte, AT.EWireless, AT.EHostess, AT.ELap, AT.EStrip, AT.EVip, AT.EConferenze, AT.EPiscina, AT.ETennis, AT.EFrigobar, AT.ECassaforte, AT.ETennis, AT.EPalestra, AT.ESpiaggia, AT.EGuardaroba, AT.Foto1, AT.Foto2, AT.Foto3, PR.BConsentita, PR.MailPrenotazione, PR.ReferentePrenotazione, CI.NomeCitta, TIAT.TipoAttivita,  TIAT.NomeCriterio1, TIAT.NomeCriterio2, TIAT.NomeCriterio3, TIAT.NomeCriterio4 FROM tblATTIVITA AS AT, tblCITTA AS CI, tblTIPOATTIVITA AS TIAT, tblPRENOTA AS PR WHERE AT.IDCITTA = CI.IDCITTA AND AT.idTIPOATTIVITA=TIAT.idTIPOATTIVITA AND PR.IDATTIVITA = AT.IDATTIVITA AND AT.IDATTIVITA=".$this->IDATTIVITA;
            
    $this->eseguo mysql_query($this->query,$this->db) or die ("Errore nella query numero: ".mysql_errno()." Descrizione: ".mysql_error());
            
    $this->row mysql_fetch_array($this->eseguo);
            return 
    $this->row;
            }
            
            function 
    elaboraRecord($row){
            
    // SETTO I PERCORSI DEI CRITERI
            
    $this->row['PercorsoCriterio1'] =  strtolower($this->row[NomeCriterio1])."/".strtolower(substr($this->row[NomeCriterio1],0,1))."_".$this->row[VotoCriterio1].".gif";
            
    $this->row['PercorsoCriterio2'] =  strtolower($this->row[NomeCriterio2])."/".strtolower(substr($this->row[NomeCriterio2],0,1))."_".$this->row[VotoCriterio2].".gif";
            
    $this->row['PercorsoCriterio3'] =  strtolower($this->row[NomeCriterio3])."/".strtolower(substr($this->row[NomeCriterio3],0,1))."_".$this->row[VotoCriterio3].".gif";
            
    $this->row['PercorsoCriterio4'] =  strtolower($this->row[NomeCriterio4])."/".strtolower(substr($this->row[NomeCriterio4],0,1))."_".$this->row[VotoCriterio4].".gif";
            
    //COSTRIUSCO IL PERCORSO DELLE FOTO
                //PRIMA
                
    if($this->row['Foto1']){
                
    $this->row['Foto1']=$this->percorso_foto."/".$this->row['Foto1'];
                }else{
                
    $this->row['Foto1']=$this->percorso_foto."/no_foto.jpg";
                }
                
    //SECONDA
                
    if($this->row['Foto2']){
                
    $this->row['Foto2']=$this->percorso_foto."/".$this->row['Foto2'];
                }else{
                
    $this->row['Foto2']=$this->percorso_foto."/no_foto_2.jpg";
                }
                
    //TERZA
                
    if($this->row['Foto3']){
                
    $this->row['Foto3']=$this->percorso_foto."/".$this->row['Foto3'];
                }else{
                
    $this->row['Foto3']=$this->percorso_foto."/no_foto.jpg";
                }
            
    //COSTRUISCO IL NOME DELLA CITTA' PER CHIAMARE LA FOTO
            
    $this->row[NomeCittaFoto]= strtolower($this->row[NomeCitta]);
            
    //ESEGUO IL PARSING DEI DATI SENSIBILI
            
    $this->row['NomeAttivita']= htmlentities($this->row[NomeAttivita]);
            
    $this->row['DescrizioneAttivita']= htmlentities($this->row[DescrizioneAttivita]);
            
    $this->row['ComeArrivare']= htmlentities($this->row[ComeArrivare]);
            return 
    $this->row;
            }
            
            
    // FUNZIONE ESTRAPOLA I COMMENTI (SE PRESENTI)
            
    function estrapolaUltimoCommento($IDATTIVITA,$stampa){
            
    $this->queryUltimoCommento="SELECT idUTENTE, Nick, WebSite, Email, TitoloCommento, Commento, DataCommento, Bpubblicato FROM tblCOMMENTI WHERE idATTIVITA=".$this->IDATTIVITA." ORDER BY DataCommento DESC";
            
    $this->eseguoUltimoCommento mysql_query($this->queryUltimoCommento,$this->db) or die ("Errore nella query Ultimo Commento: ".mysql_errno()." Descrizione: ".mysql_error());
                
    //SE STAMPO E' 1 STAMPO I COMMENTO
                    
    if($this->stampa==1){
                            while(
    $this->ultimoCommento $this->elaboraUltimoCommento(mysql_fetch_array($this->eseguoUltimoCommento))){
                            
                            echo
    "
                            <p class=\"commenti_ajax\">
                            <img src=\"img/avatar.gif\" class=\"avatar\" />
                            <span class=\"titolo_commenti\">"
    .$this->ultimoCommento[TitoloCommento]."</span>

                            <span class=\"corpo_commenti\">"
    .$this->ultimoCommento[Commento]."</span>

                            <span class=\"coda_commenti\">Rilasciato da 
    $ultimoCommento[Link] il [i]$ultimoCommento[GiornoCommento] alle ore $ultimoCommento[OraCommento][/i]</span>
                            </p>
                            "
    ;
                            }
                    }
                    
    //ALTRIMENTO ESEGUO LA FUNZIONE NORMALMENTE
                    
    else {
                    
    $this->ultimoCommento mysql_fetch_array($this->eseguoUltimoCommento);
                    
    $this->ultimoCommento['numero']= mysql_num_rows($this->eseguoUltimoCommento);
                    }
                if(!
    $this->ultimoCommento){
                
    $this->ultimoCommento['numero']="0";
                return 
    $this->ultimoCommento;
                } else {
                return 
    $this->ultimoCommento;
                }
            }
            
            
    // FUNZIONE CHE ELABORA I RISULTATI DEI COMMENTI
            
    function elaboraUltimoCommento($ultimoCommento){
            
    $this->ultimoCommento['TitoloCommento'] = htmlentities($this->ultimoCommento['TitoloCommento']);
            
    $this->ultimoCommento['Commento'] = htmlentities($this->ultimoCommento['Commento']);
            
    $this->ultimoCommento['Commento'] = str_replace("€","&euro;",$this->ultimoCommento['Commento']);
            
    $this->ultimoCommento['GiornoCommento'] = date("d/m/Y",$this->ultimoCommento['DataCommento']);
            
    $this->ultimoCommento['OraCommento'] = date("G.i",$this->ultimoCommento['DataCommento']);
                if(!
    $this->ultimoCommento['Nick']){
                
    $this->ultimoCommento['Nick']= "Anonimo";
                }
                if(!
    $this->ultimoCommento['WebSite']){
                
    $this->ultimoCommento['Link']= "<a href=\"#\">".$this->ultimoCommento['Nick']."</a>";
                } else{
                
    $this->ultimoCommento['Link']= "<a href=\"".$this->ultimoCommento['WebSite']."\" target=\"_blank\">".$this->ultimoCommento['Nick']."</a>";
                }
                if(!
    $this->ultimoCommento['Mail']){
                
    $this->ultimoCommento['WebSite']= "#";
                } 
            return 
    $this->ultimoCommento;
            }
         }
    ?>

  8. #8
    Il problema è che il tuo codice NON gestisce correttamente il valore restituito da mysql_fetch_array().

    Se il parametro $ultimoCommento di elaboraUltimoCommento() è FALSE, il metodo elaboraUltimoCommento() DEVE restituire FALSE, altrimenti il ciclo while in cui lo richiami continuerà all'infinito.

  9. #9
    Ok, ho modificato la classe così:

    Codice PHP:
    // FUNZIONE ESTRAPOLA I COMMENTI (SE PRESENTI)
            
    function estrapolaUltimoCommento($IDATTIVITA,$stampa){
            
    $this->queryUltimoCommento="SELECT idUTENTE, Nick, WebSite, Email, TitoloCommento, Commento, DataCommento, Bpubblicato FROM tblCOMMENTI WHERE idATTIVITA=".$this->IDATTIVITA." ORDER BY DataCommento DESC";
            
    $this->eseguoUltimoCommento mysql_query($this->queryUltimoCommento,$this->db) or die ("Errore nella query Ultimo Commento: ".mysql_errno()." Descrizione: ".mysql_error());
                
    //SE STAMPO E' 1 STAMPO I COMMENTO
                    
    if($this->stampa==1){
                            while(
    $this->ultimoCommento mysql_fetch_array($this->eseguoUltimoCommento)){
                            
    $this->elaboraUltimoCommento($this->ultimoCommento);
                            echo
    "
                            <p class=\"commenti_ajax\">
                            <img src=\"img/avatar.gif\" class=\"avatar\" />
                            <span class=\"titolo_commenti\">"
    .$this->ultimoCommento[TitoloCommento]."</span>

                            <span class=\"corpo_commenti\">"
    .$this->ultimoCommento[Commento]."</span>

                            <span class=\"coda_commenti\">Rilasciato da"
    .$this->ultimoCommento[Link]. "il [i]".$this->ultimoCommento[GiornoCommento] ."alle ore".$this->ultimoCommento[OraCommento]."[/i]</span>
                            </p>
                            "
    ;
                            }
                    }
                    
    //ALTRIMENTO ESEGUO LA FUNZIONE NORMALMENTE
                    
    else {
                    
    $this->ultimoCommento mysql_fetch_array($this->eseguoUltimoCommento);
                    
    $this->ultimoCommento['numero']= mysql_num_rows($this->eseguoUltimoCommento);
                    }
                if(!
    $this->ultimoCommento){
                
    $this->ultimoCommento['numero']="0";
                return 
    $this->ultimoCommento;
                } else {
                return 
    $this->ultimoCommento;
                }
            }
            
            
    // FUNZIONE CHE ELABORA I RISULTATI DEI COMMENTI
            
    function elaboraUltimoCommento($ultimoCommento){
            if(!
    $this->ultimoCommento){
            
    $this->ultimoCommento=FALSE;
            return 
    $this->ultimoCommento;
            break;
            }
            
    $this->ultimoCommento['TitoloCommento'] = htmlentities($this->ultimoCommento['TitoloCommento']);
            
    $this->ultimoCommento['Commento'] = htmlentities($this->ultimoCommento['Commento']);
            
    $this->ultimoCommento['Commento'] = str_replace("€","&euro;",$this->ultimoCommento['Commento']);
            
    $this->ultimoCommento['GiornoCommento'] = date("d/m/Y",$this->ultimoCommento['DataCommento']);
            
    $this->ultimoCommento['OraCommento'] = date("G.i",$this->ultimoCommento['DataCommento']);
                if(!
    $this->ultimoCommento['Nick']){
                
    $this->ultimoCommento['Nick']= "Anonimo";
                }
                if(!
    $this->ultimoCommento['WebSite']){
                
    $this->ultimoCommento['Link']= "<a href=\"#\">".$this->ultimoCommento['Nick']."</a>";
                } else{
                
    $this->ultimoCommento['Link']= "<a href=\"".$this->ultimoCommento['WebSite']."\" target=\"_blank\">".$this->ultimoCommento['Nick']."</a>";
                }
                if(!
    $this->ultimoCommento['Mail']){
                
    $this->ultimoCommento['WebSite']= "#";
                } 
            return 
    $this->ultimoCommento;
            } 
    Primo la funzione la richiamo dall'interno del ciclo while (il vero problema era quello), secondo in caso di dato falso ritorno falso...

    Ti sembra corretto?

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.