Jump to content

Adding dropdown pagination limit


Russia

Recommended Posts

Im trying to add a pagination limit to my pagination script, so I can limit the amount.

 

I got this working when the page is loaded with a number at the end like:

 

http://www.example.com?limit=10

 

How  do I do it so it automatically sets the number to 5 when there is no variable?

 

<form>
<select name="file" size="1"
  onchange="loadPage(this.form.elements[0])" target="_parent._top"
            <option value="?limit=9">9</option>
            <option value="?limit=15">15</option>
            <option value="?limit=30">30</option>
            <option value="?limit=all">All</option>
</select>
</form>


<?php

require_once("inc/config.php");
if (isset($_POST['del'])) 
{
  for ($count = 0;$count<count($_POST[delchk]);$count++)
    {
           $delete = $_POST[delchk][$count];
           $query = "DELETE FROM accounts WHERE id = '$delete'";
           $result = mysql_query($query);
           if (!$result) 
        {
            die("Error deleting accounts! Query: $query<br />Error: ".mysql_error());
        }
    }
}
$result = mysql_query("SELECT * FROM accounts");
if(mysql_num_rows($result) > 0)
{
  echo "<table class=\"gridtable\">
<thead>
    <tr>
        <th align=\"center\" scope=\"col\">Username</th>
        <th align=\"center\" scope=\"col\">Password</th>
        <th align=\"center\" scope=\"col\">Highscores</th>
        <th align=\"center\" scope=\"col\">Date</th>
        <th align=\"center\" scope=\"col\">IP Address</th>
        <th align=\"center\" scope=\"col\">Status</th>
       <th align=\"center\" scope=\"col\">Delete?</th>
    </tr>
</thead>
<tbody>";
echo "<form name = 'myform' action='' method='post'>";
$data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
$rows = mysql_num_rows($data);
[b]$page_rows = $_GET["limit"];[/b]
if(!isset($_GET['pagenum']))
{
$page = 1;
}
else
{
$page = (int) $_GET['pagenum'];
}
?>

 

I get this error when I try to load the page like: http://www.example.com

 

Warning: Division by zero in /home/cherdak/public_html/accounts.php on line 310

Warning: Division by zero in /home/cherdak/public_html/accounts.php on line 311
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

 

but no error when I load the page like: http://www.example.com?limit=10

 

 

I made bold where the $_Get is.

Link to comment
https://forums.phpfreaks.com/topic/180753-adding-dropdown-pagination-limit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.