Rieccomi, piano piano ma mi avvicino sempre più al mio obiettivo!
Ti ringrazio Badaze il tuo codice mi è servito a capire qualcosa in più!
Allora ho fatto dei progressi adesso nella mia pagina news vedo solamente i primi 4 risultati per poi vedere gli altri nelle pagine successive.
Mi sono un po arenato sulla creazione del menu per navigare tra le varie pagine, mi sono un po arrangiato ma sicuramente la mia non è una soluzione definitiva. Vorrei riuscire a utilizzare il tuo suggerimento per creare i link a tutte le pagine in automatico!
Cerco di spiegarti il mio problema:
Se calcolo la variabile $nbPages all'interno della mia funzione nel file function.php poi non riesco a richiamarla nel file news.php.
e purtroppo senza quella variabile non posso impostare il menu di navigazione...
ho anche pensato di farlo al contrario, calcolare la variabile $nbPages direttamente all'interno di news.php ma mi ritrovo con lo stesso problema non riesco a reperire $max (il numero totale di record)
di seguito i due file aggiornati:
pagina news.php
Codice PHP:
<?php
include_once("php/connection.php");
$posts = ( isset($_GET['page']) ) ? get_posts(null, null, 2014, $_GET['page']) : get_posts(null, null, 2014, $_GET = 1);
$np = ($_GET['page']) + 1;
if ($np < 3)
{
$np = 2;
}
$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="articolo/<?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="news/<?php echo $np ?>">PAGINA SUCCESSIVA</a> </p>
<p> <a href="yearnews/2013">2013</a> </p>
<p> <a href="yearnews/2012">2012</a> </p>
<?php include("php/footer.php");?>
</body>
</html>
function.php
Codice PHP:
<?php
function get_posts($url = null, $cat_id = null, $year = 2014, $page = 1)
{
$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";
if ( isset($page) )
{
$lines = 4;
$first = ($page - 1) * $lines;
$query .= " LIMIT $first,$lines";
}
$query = mysql_query($query);
while ( $row = mysql_fetch_assoc($query) )
{
$posts[] = $row;
}
return $posts;
}