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

    comments(); non funzia.

    Codice PHP:
    class news
    {
        var 
    $id;
        function 
    news(){
            
    $MySql "SELECT COUNT(id)  AS totale FROM news";
            
    $query mysql_query ($MySql) or die ( "Non riesco ad eseguire la richiesta $MySql"); 
            while (
    $valori mysql_fetch_array ($query)){ 
                
    // numero totale di records
                
    $tot_records $valori["totale"];
             }
            
    // risultati per pagina(secondo parametro di LIMIT)
            
    $per_page 5;

            
    // numero totale di pagine
            
    $tot_pages ceil($tot_records $per_page);

            
    // pagina corrente
            
    if ($this->id == "") {
                
    $leo "1";
            } else {
                
    $leo $this->id;
            }
            
    $current_page = (!$leo) ? : (int)$leo;
            
    $query='SELECT * FROM news ORDER BY id ASC LIMIT 0,5';
            
    $q=mysql_query($query);
            
    $news .='<div align="left"><ul id="newslist">';
            while(
    $res=mysql_fetch_array($q)){
                if(
    $res['comments_id'] == '0'){
                    
    $descrizione=$res['description'];
                    
    $descrizione .= @eregi_replace('/\[(quote)\](.*?)\[\/(quote)\]/is','<div id="quote">$2</div>',$descrizione);
                    
    $news .='[*]<div id="news">
                                <table width="75%" border="0" cellpadding="0" cellspacing="0">
                                
                                <tr>
                                <td width="50%" height="16" valign="top">'
    .$res['title'].'</td>
                                <td width="25%" valign="top">Data : '
    .$res['date'].'</td>
                                </tr>
                                <tr>
                                <td height="49" colspan="2" valign="top">'
    .$descrizione.'</td>
                                </tr>
                                </table>
                            </div><hr>'
    ;
                } else {
                    
    $news .='[*]<div id="news">
                            <table width="75%" border="0" cellpadding="0" cellspacing="0">
                            
                            <tr>
                            <td width="50%" height="16" valign="top">'
    .$res['title'].'</td>
                            <td width="25%" valign="top">Data : '
    .$res['date'].'</td>
                            </tr>
                            <tr>
                            <td height="49" colspan="2" valign="top">'
    .$res['description'].'</td>
                            </tr>
                            <td height="17" colspan="2" valign="top">[url="javascript:javascript:callAHAH(\'index.php?idnews='
    .$res['id'].'&page=main&func=comments\',\'tcc\',\'<img src=immagini/loading.gif border=0>\',\'Error:\')"]Commenti[/url]</td>
                            </table>
                        </div>'
    ;
                }
            }
                
    $paginazione "Pagine totali: " $tot_pages "
    ["
    ;
                for(
    $i 1$i <= $tot_pages$i++) {
                    if(
    $i == $current_page) {
                        
    $paginazione .= $i " ";
                    } else {
                        
    $paginazione .= '|<a href=\"javascript:callAHAH(\'index.php?id=$i&page=main\',\'content\',\'<img src=immagini/loading.gif border=0>\',\'Error:\')\" title=\"Vai alla pagina $i\">$i</a>|';
                    }
                }
                
    $paginazione .= "]";
            
    $news .='[/list]<div>'.$paginazione.'</div></div>';
            return 
    $news;
        }
        function 
    comment($param){
            
    $MySql='SELECT * FROM comments WHERE idnews="'.$param.'" ORDER BY idnews ASC LIMIT 0,5';
            
    $query=mysql_query($MySql) or die(mysql_error());
            while(
    $result=mysql_fetch_array($query) or die(mysql_error())){
                
    $comment ='<div id="comments">'.$result['description'].'</div><hr />';
            }
            return 
    $comment;
        }

    Ho questa classe che una volta settati i parametri mostra le news.
    fino a qui tutto bene, ma poi non mi funziona la funzione comments.
    non mi scrive a video.
    cosa ho sbagliato?
    NB : il forum mi ha cancellato gli escape

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    Non credo tu possa usare una variabile chiamata allo stesso modo della funzione.
    Mi riferisco a comment
    Conosci te stesso(?)
    (..e allora perchè scassi a me? )

  3. #3
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Non vedo dove la chiami, quella funzione

  4. #4
    Ho modificato la classe in modo tale da avere solo una funzione.
    Codice PHP:
    <?php
    class news
    {
        var 
    $param;
        var 
    $id;
        function 
    news(){
            if(
    $this->param=="mostra"||$this->param==""){
            
    $MySql "SELECT COUNT(id)  AS totale FROM news";
            
    $query mysql_query ($MySql) or die ( "Non riesco ad eseguire la richiesta $MySql"); 
            while (
    $valori mysql_fetch_array ($query)){ 
                
    // numero totale di records
                
    $tot_records $valori["totale"];
             }
            
    // risultati per pagina(secondo parametro di LIMIT)
            
    $per_page 5;

            
    // numero totale di pagine
            
    $tot_pages ceil($tot_records $per_page);

            
    // pagina corrente
            
    if ($this->id == "") {
                
    $leo "1";
            } else {
                
    $leo $this->id;
            }
            
    $current_page = (!$leo) ? : (int)$leo;
            
    $query='SELECT * FROM news ORDER BY id ASC LIMIT 0,5';
            
    $q=mysql_query($query);
            
    $news .='<div align="left"><ul id="newslist">';
            while(
    $res=mysql_fetch_array($q)){
                if(
    $res['comments_id'] == '0'){
                    
    $descrizione=$res['description'];
                    
    $descrizione .= @eregi_replace('/\[(quote)\](.*?)\[\/(quote)\]/is','<div id="quote">$2</div>',$descrizione);
                    
    $news .='[*]<div id="news">
                                <table width="75%" border="0" cellpadding="0" cellspacing="0">
                                
                                <tr>
                                <td width="50%" height="16" valign="top">'
    .$res['title'].'</td>
                                <td width="25%" valign="top">Data : '
    .$res['date'].'</td>
                                </tr>
                                <tr>
                                <td height="49" colspan="2" valign="top">'
    .$descrizione.'</td>
                                </tr>
                                </table>
                            </div><hr>'
    ;
                } else {
                    
    $news .='[*]<div id="news">
                            <table width="75%" border="0" cellpadding="0" cellspacing="0">
                            
                            <tr>
                            <td width="50%" height="16" valign="top">'
    .$res['title'].'</td>
                            <td width="25%" valign="top">Data : '
    .$res['date'].'</td>
                            </tr>
                            <tr>
                            <td height="49" colspan="2" valign="top">'
    .$res['description'].'</td>
                            </tr>
                            <td height="17" colspan="2" valign="top">[url="javascript:callAHAH(\'index.php?idnews='
    .$res['id'].'&page=main&func=comments\',\'tcc\',\'<img src=immagini/loading.gif border=0>\',\'Error:\')"]Commenti[/url]</td>
                            </table>
                        </div>'
    ;
                }
            }
                
    $paginazione "Pagine totali: " $tot_pages "
    ["
    ;
                for(
    $i 1$i <= $tot_pages$i++) {
                    if(
    $i == $current_page) {
                        
    $paginazione .= $i " ";
                    } else {
                        
    $paginazione .= '|<a href=\"javascript:callAHAH(\'index.php?id=$i&page=main\',\'content\',\'<img src=immagini/loading.gif border=0>\',\'Error:\')\" title=\"Vai alla pagina $i\">$i</a>|';
                    }
                }
            
    $paginazione .= "]";
            
    $news .='[/list]<div>'.$paginazione.'</div></div>';
            } elseif(
    $this->param=="comment") {
                
    $MySql='SELECT * FROM comments WHERE idnews="'.$param.'" ORDER BY idnews ASC LIMIT 0,5';
                
    $query=mysql_query($MySql) or die(mysql_error());
                while(
    $result=mysql_fetch_array($query) or die(mysql_error())){
                    
    $news ='<div id="comments">'.$result['description'].'</div><hr />';
                }
            }
        return 
    $news;    
        }
    }
    ?>
    la funzione è richiamata così:
    Codice PHP:
    <?php
    include('includes/php/news.class.php');
    $news=new news;
    $news->id=@$_GET['id'];
    $news->param=@$_GET['func'];
    $func=$news->news();
    $smarty->assign('news',$func);
    ?>

    grazie in anticipo.

  5. #5
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    (editato)

    Usi gli oggetti in modo un po' strano... un costruttore non dovrebbe restituire un valore

  6. #6
    non capisco che cosa intendi per
    Usi gli oggetti in modo un po' strano... un costruttore non dovrebbe restituire un valore

    io non so usare gli oggetti, quindi mi potrsti spiegare un po meglio?

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.