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