All pastes #565903 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-14 06:38 UTC
rendered paste body
<?php
include("include/config.php");
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Define the number of results per page
$max_results = 5;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results

$sql = mysql_query("SELECT * FROM Articles, Genres WHERE Articles.GenreID = Genres.GenreID ORDER BY Articles.Name DESC LIMIT $from, $max_results");

while($Rij = mysql_fetch_array($sql)){
    // Build your formatted results here.
	echo ("<table>");
		echo ("<tr>");
		echo ("<td><img width=150 height=150 src='$Rij[Picture]' border='0' align='left' title='$Rij[Description]' alt='$Rij[Description]' style='border:0px solid black;'><br></td>");
		echo ("<td><br><br><b>Genre:</b> $Rij[Gname]<br>");
		echo ("<b>Article name:</b> $Rij[Name]<br>");
		echo ("<b>Article description:</b> $Rij[Description]<BR><BR></td>");
		echo ("</tr>");
    echo ("</TABLE>");
}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Articles"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?>