Buonasera,
sono un autodidatta e nei ritagli di tempo stò provando a programmare un piccolo blog utilizzando PHP e MYSQL. Per il momento, anche se con qualche difficoltà ho creato la base quindi visualizzazione delle news, catalogazione in categorie e anche in anni. Tutto sembra funzionare.

Ora, passiamo alla parte problematica:
come potrei ottenere la paginazione delle news stesse? In sostanza vorrei che le pagine conteneti i risultati delle query (news, categorienews e annonews) restituiscano un numero fisso di risultati per poi andare a mettere le rimanenti su altre pagine.

Potreste mettermi sulla strada giusta?

Di seguito il codice (spero non ci siano troppi errori)...

pagina news.php
Codice PHP:
<?php
include_once("php/connection.php");
$posts get_posts();

$query mysql_query("SELECT page_title,meta_key,meta_desc FROM `page_att` WHERE page_name = 'news'");
$row mysql_fetch_array($query);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $row['page_title']; ?></title>
<meta name="keywords" content="<?php echo $row['meta_key']; ?>" />
<meta name="description" content="<?php echo $row['meta_desc']; ?>" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="favicon.ico" />
</head>

<body>
<?php include("php/header.php");?>
<h1> Tullio News </h1>

<?php
foreach ( $posts as $post )
{
    
?>
    <h2><a href="news/<?php echo $post['url']; ?>"><?php echo $post['title']; ?></a></h2>
    <p> Articolo del <?php echo date('d-m-y'strtotime($post['date_posted'])) ?>
    in <a href="catnews/<?php echo $post['name']; ?>"><?php echo $post['name']; ?></a> </p>
    <p> <?php echo nl2br($post['contents']); ?> </p>
    <?php
}
?>
<p> <a href="yearnews/2013">2013</a> </p>
<p> <a href="yearnews/2012">2012</a> </p>

<?php include("php/footer.php");?>

</body>
</html>

File function.php (contente get_posts)
Codice PHP:
<?php
function get_posts($url null$cat_id null$year 2014)
{
    
$posts = array();
    
$query "SELECT `posts`.`id` AS `post_id`, `categories`.`id` AS `category_id`,
                    `url`, `year`, `title`, `contents`, `date_posted`, `categories`.`name`
            FROM `posts`
            INNER JOIN `categories` ON `categories`.`id` = `posts`.`cat_id`"
;
    
    if ( isset(
$url) )
    {
        
$query .= " WHERE `url` = '{$url}'";
    }
    
    if ( isset(
$cat_id) )
    {
        
$query .= " WHERE `name` = '{$cat_id}'";
    }
    
    if ( isset(
$year) )
    {
        
$query .= " WHERE `year` = '{$year}'";
    }
    
    
$query .= " ORDER BY `posts`.`id` DESC";
    
    
$query mysql_query($query);
    
    while ( 
$row mysql_fetch_assoc($query) )
    {
        
$posts[] = $row;
    }
    
    return 
$posts;
}

file .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^news/([^/]+) articolo.php?url=$1 [L]
RewriteRule ^catnews/([^/]+) catnews.php?cat_id=$1 [L]
RewriteRule ^yearnews/([^/]+) yearnews.php?year=$1 [L]
RewriteRule ^()$ index.php [NC,L]
Rewritecond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteRule (.*)$ $1.php [NC]