On my site I want to use a limit to make sure there are no more then 10 items on a page. I have made something but for some reason it doesn't work. It shows me how many pages I should have, but it still makes one page of it (in my example I should have 2 pages, this is also what he says at the bottom of the site).
This is my code, does any know what goes wrong here?:
<?
$server = localhost;
$database = dbase;
$username = user;
$password = w8woord;
$link = mysql_connect("$server", "$username", "$password") or die("Could not connect to server");
mysql_select_db("$database") or die("Could not select database");
$sql_query = mysql_query("SELECT * FROM unreal WHERE part = 'map' AND subpart = 'Deathmatch' AND game = 'ut' ORDER BY id DESC");
$num_items = mysql_num_rows($sql_query);
if($num_items == '') {
$num_items = "0";
}
$num_per_page = 10;
$num_pages = ceil($num_items/$num_per_page);
if($num_pages == '0') {
$num_pages = 1;
}
if(!isset($current_page)) {
$current_page = 1;
}
if ($_GET['order'])
{
if ($_GET['order'] == rating)
{
$orderby = " ".$_GET['order']." desc";
}
elseif ($_GET['order'] == date)
{
$orderby = " ".$_GET['order']." desc";
}
elseif ($_GET['order'] == downloads)
{
$orderby = " ".$_GET['order']." desc";
}
else
{
$orderby = " ".$_GET['order'];
}
}
else
{
$orderby = " id";
}
{
$start_value = ($current_page * 10) - 10;
$result = mysql_query("SELECT * FROM unreal WHERE part = 'map' AND subpart = 'Deathmatch' AND game = 'ut' ORDER BY" . $orderby . " LIMIT " . $start_value . " , 10") or die("Query failed in file " . __FILE__ . " on line " . __LINE__ . ", mysql-error: " . mysql_error() . "<BR>Query: " . $query);
?>
<TABLE borderColor=#111111 cellSpacing=3 cellPadding=5 width="100%" border=0>
<TR>
<TD align=middle colSpan=2>
<TABLE borderColor=#111111 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
<TD><B>
<p><span style='font-size:15.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'>Deathmatch Maps</span></p></B>
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>Sort By</B>
[ <A href="<?php echo $_SERVER['PHP_SELF']; ?>?order=addon">Name</A>
| <A href="<?php echo $_SERVER['PHP_SELF']; ?>?order=author">Author</A>
| <a href="<?php echo $_SERVER['PHP_SELF']; ?>?order=rating">Rating</a>
| <A href="<?php echo $_SERVER['PHP_SELF']; ?>?order=date">Date</A>
| <A href="<?php echo $_SERVER['PHP_SELF']; ?>?order=downloads">Downloads</A>
]</span></p> </TD></TR></TABLE>
</TD></TR>
<?
while ($p = mysql_fetch_assoc($result)) {
echo "<TR>
<TD width=100% background=\"../image/uttitle.jpg\" colSpan=2>
<p><span style='font-size:10.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>
<A href=\"addon.php?addon=".$p['id'] ."\">".$p['addon'] ."</a></B></span></P></TD></TR>
<TR>
<TD align=right>
<TABLE borderColor=#111111 cellSpacing=4 cellPadding=0 width=400 border=0>
<TR>
<TD vAlign=top width=\"25%\" rowspan=5>
<A href=\"addon.php?addon=".$p['id'] ."\">
<IMG height=100 src=../addonpics/".$p['id'] .".gif border=0></A></TD>
<TD vAlign=top width=\"25%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>Author:</B></span></p></TD>
<TD vAlign=top width=\"50%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>Average rating:</B></span></p></TD></TR>
<TR>
<TD vAlign=top width=\"25%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><A href=mailto:".$p['email'] .">".$p['author'] ."</A></span></p></TD>
<TD vAlign=top width=\"50%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'>".$p['rating'] ."</span></p></TD></TR>
<TR>
<TD vAlign=top width=\"25%\"> </TD>
<TD vAlign=top align=left width=\"50%\"> </TD></TR>
<TR>
<TD vAlign=top width=\"25%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>Date Published:</B></span></p></TD>
<TD vAlign=top align=left width=\"50%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><B>Number of downloads:</B></span></p></TD></TR>
<TR>
<TD vAlign=top width=\"25%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'>".$p['date'] ."</span></p></TD>
<TD vAlign=top align=left width=\"50%\">
<p><span style='font-size:7.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'>".$p['downloads'] ."</span></p></TD></TR>
</TABLE></TD></TR>";
}
if(!isset($current_page)) {
$current_page = 1;
}
if($current_page != 1){
$prev_page = $current_page-1;
$prev = '<a href="'.$_SERVER['PHP_SELF'].'?current_page='.$prev_page.'">Back</a>';
} else {
$prev = "Back";
}
if(($num_messages - ($num_per_page * $current_page)) > 0) {
$next_page = $current_page+1;
$next = '<a href="mapdm.php?current_page='.$next_page.'">Next</a>';
} else {
$next = "Next";
}
?> <TR>
<TD align=middle width="100%" colSpan=2>
<p><span style='font-size:8.0pt;mso-bidi-font-size:7.5pt;font-family:
Verdana;color:cornflowerblue'><? echo "Page ".$current_page." of ".$num_pages."<BR>[ ".$prev." | ".$next." ]"; ?> </span></p>
</TD></TR></table>
<?
mysql_free_result($result);
}
?>