Ett stycke php-kod:
<?php
//connecting to the database
$error = "Could not connect to the database";
mysql_connect('localhost','root','') or die($error);
mysql_select_db('db1') or die($error);
//max displayed per page
$per_page = 5;
//get start variables
$start = $_GET['start'];
//count_records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM news_nyheter"));
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if(!$start){
$start = 0;
}
//display data
$get = mysql_query("SELECT * FROM news_nyheter LIMIT $start, $per_page");
while($row = mysql_fetch_assoc($get)){
//get data
$title = $row['title'];
$text = $row['text'];
$date = $row['date'];
$author = $row['author'];
echo $title . "<br>";
echo $text . "<br>";
echo "Skrivet " . $date . " av " . $author . ".<br><br><br>";
}
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if(!($start<=0)){
echo "<a href='index.php?start=$prev'>Prev</a> ";
}
//show next button
if(!($start>=$record_count-$per_page)){
echo " <a href ='index.php?start=$next'>Next</a>";
}
?>
Jag hette tidigare ...