Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Problema MySQL/PHP

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2009
    Messaggi
    3

    Problema MySQL/PHP

    Codice PHP:
    <?php

    $limit 
    5// articoli per pagina

    $mysql = new mysqli('localhost''pokemonc_01''*****''pokemonc_db');
    if(!
    $mysql)
    {
        die(
    "Errore di connessione al database, impossibile procedere");
    }

    $Comment strip_tags($_GET['id']);

    $result $mysql->query("SELECT COUNT(*) AS tot FROM articoli")->fetch_assoc();

    $page = isset($_GET['p']) ? $_GET['p'] : 1;
    $totals $result['tot'];
    $totals_pages ceil($totals $limit);

    $articles $mysql->query("
        SELECT
            AR.id AS id,
            AR.title AS title,
            AR.article AS content,
            AU.username AS author,
            AR.data AS data,
            AR.ora AS ora,
            AR.categoria AS cat
        FROM
            articoli AR,
            utenti AU
        WHERE
            AU.username = AR.author
        ORDER BY id DESC
        LIMIT "
    .(($page 1) * $limit).",".$limit);

    ?>

    <table cellspacing="0">
                <?php
                
    while($article $articles->fetch_assoc())
                {
                    
    printf('<tr><td background="http://pokemoncentral.net/Immagini/news_01.png" style="width: 800px;height:70px; background-repeat: no-repeat"><div class="news_top">[url="./?act=ShowNews&id='.$article["]'.$article["title"].'[/url]</div></td></tr>
            <tr><td background="
    http://pokemoncentral.net/Immagini/news_02.png" style="width: 800px;background-repeat: repeat-y"><div class="news_content">
                
    '.$article["content"].'
            
    </div>
            </
    td></tr>
            <
    td background="http://pokemoncentral.net/Immagini/news_03.png" style="width: 800px;height:41px; background-repeat: no-repeat"><div class="news_footer">[i]Postato da '.$article["author"].' il '.$article["data"].' alle '.$article["ora"].' in: [b]'.$article["cat"].', [url="./?act=ShowNews&id='.$article["]Commenta! ( '.$totale.' Commenti )[/url][/b][/i]</div></td></tr>');
                }
                ?>
                </table>
            

    Pagina <?php echo 
    $page; ?> di <?php echo $totals_pages; ?> 

            <?php
            if(
    $page - 1 > 0)
            {
                echo '[url="
    ./?act=News&p='.($page - 1).'"]&lt; Precedente[/url] | ';
            }else
            {
                echo '&lt; Precedente | ';
            }
            if(
    $page + 1 <= $totals_pages)
            {
                        echo '[url="
    ./?act=News&p='.($page + 1).'"]Successiva &gt;[/url]';
            }else
            {
                        echo 'Successiva &gt;';
            }
            ?>
            </p>
    Se io volessi far vedere il numero di commenti scritti, data l'id della news, come dovrei scrivere "$totale"?

  2. #2
    Utente di HTML.it L'avatar di zeroh
    Registrato dal
    Feb 2002
    Messaggi
    138
    Ciao,
    credo di non aver capito bene il tipo di problema o soluzione che cerchi.
    Potresti spiegarti meglio?

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2009
    Messaggi
    3
    Ho risolto, alla fine dovevo mettere il count dopo il while, ecco perchè non funziava.

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.