Jump to content

[SOLVED] data through pages


contra10

Recommended Posts

I'm trying to do this pagination script but everytime i click on "page 2" or "last" i get the same data in page one, basically nothing happens except for the url that changes

 

from something like this

http://localhost/outdoor/next/

to

http://localhost/outdoor/next/index.php?pagenum=2

<?php 
// Connects to your Database 
mysql_connect("localhost", "", "") or die(mysql_error()); 
mysql_select_db("deals") or die(mysql_error()); 

//This checks to see if there is a page number. If not, it will set it to page 1 
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

//Here we count the number of results 
//Edit $data to be your query 
$querye = "SELECT * FROM `deal` WHERE `category` = 'Outdoor' and `time` = '704'";
$result = mysql_query($querye) or die(mysql_error());
$rows= mysql_num_rows($result);

//This is the number of results displayed per page 
$page_rows = 2; 
$es = ($rows/$page_rows);
//This tells us the page number of our last page 
$last = ceil($es);

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

//This sets the range to display in our query 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM `deal` WHERE category = 'Outdoor' and time = '704' $max") or die(mysql_error()); 

//This is where you display your query results
while ($postede = mysql_fetch_assoc($data_p))
{
$title = "{$postede['title']}";
$imagename = "{$postede['imagename']}";
$time = "{$postede['time']}";
$titled = stripslashes($title);
$url = "{$postede['url']}";
$on= "on";
$off= "off";
echo "<tr>"; 
echo"<td width='10%' height='200'><a href='$url' target='_blank'><img src='http://localhost/includes/704/$imagename.jpg'></a></td>";
echo "</tr>"; 
echo "<tr><td></td></tr>";	
}
echo"<p>";

// This shows the user what page they are on, and the total number of pages
echo " --Page $pagenum of $last-- <p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?p=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?p=$previous'>$Previous</a> ";
} 

//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?p=$next'>$next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?p=$last'>Last ->></a> ";
} 
?> 

Link to comment
Share on other sites

Hi could you try

 

<?php 
// Connects to your Database 
mysql_connect("localhost", "", "") or die(mysql_error()); 
mysql_select_db("deals") or die(mysql_error()); 

$pagenum = 1;

//This checks to see if there is a page number. If not, it will set it to page 1 
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

//Here we count the number of results 
//Edit $data to be your query 
$querye = "SELECT * FROM `deal` WHERE `category` = 'Outdoor' and `time` = '704'";
$result = mysql_query($querye) or die(mysql_error());
$rows= mysql_num_rows($result);

//This is the number of results displayed per page 
$page_rows = 2; 
$es = ($rows/$page_rows);
//This tells us the page number of our last page 
$last = ceil($es);

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

//This sets the range to display in our query 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM `deal` WHERE category = 'Outdoor' and time = '704' $max") or die(mysql_error()); 

//This is where you display your query results
while ($postede = mysql_fetch_assoc($data_p))
{
   $title = "{$postede['title']}";
$imagename = "{$postede['imagename']}";
$time = "{$postede['time']}";
$titled = stripslashes($title);
$url = "{$postede['url']}";
$on= "on";
$off= "off";
   echo "<tr>"; 
echo"<td width='10%' height='200'><a href='$url' target='_blank'><img src='http://localhost/includes/704/$imagename.jpg'></a></td>";
   echo "</tr>"; 
   echo "<tr><td></td></tr>";   
}
echo"<p>";

// This shows the user what page they are on, and the total number of pages
echo " --Page $pagenum of $last-- <p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?p=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?p=$previous'>$Previous</a> ";
} 

//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?p=$next'>$next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?p=$last'>Last ->></a> ";
} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.