Jump to content

[SOLVED] pagination & $_GET[];


Ltj_bukem

Recommended Posts

Hi, I have a simple query that returns a set of results using pagination. It basically checks a table that contains every name, date and index of  pdf's they have downloaded. However, I have set a limit of 10 results per page

but for some reason the first page displays all of the results, as does the second page, third page and so on.

 

Here's the code

 

<?php


          $pagenum = $_GET['pagenum'];

if (isset($_SESSION['valid_user']) )
  {
      $username=$_SESSION['valid_user'];
    
  }
   else
  {
    $username=$_SESSION['valid_user'];
    }
                   
	echo"username=$username";
	echo "<br></br>";






mysql_connect("", "", "") or die(mysql_error());

mysql_select_db("") 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;

}

echo"pagenum=$pagenum";


$data = mysql_query("SELECT username,pdf_id,date,name FROM user_history WHERE username = '$username'")or die(mysql_error());

$rows = mysql_num_rows($data);

echo "rows = $rows";
echo "<br></br>";



//This is the number of results displayed per page

$page_rows = 11;



//This tells us the page number of our last page

$last = ceil($rows/$page_rows);

$total_pages = ceil($rows/$page_rows);



//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;

echo "max =$max";    

//This sets the  query again, the same one... 

$data_p = mysql_query("SELECT username,pdf_id,date,name FROM user_history WHERE username = '$username'") or die(mysql_error());


//This is where you display your query results
?>
</p16>
<p16>
<table border = "0" align = "center" >
           <tr>
                    
            <th align='left' ><font size='2' font color = '#ffffff' >username</th>
           
           <th align='left' > <font size='2' font color = '#ffffff'>pdf_id</th>
           
            <th align='left' > <font size='2' font color = '#ffffff'>date</th>
          
     
           </tr>
          
           
           
           
<?php

echo"<br>";
echo"<br>";

while (list($username,$pdf_id,$date,$name) = mysql_fetch_array($data_p))    {
echo "<tr >";

echo  "<td width = '200' height = '1' align = 'left'><font size='2'font color = '#ffffff' face='Arial'>$username</td>";

//echo  "<td width = '150' height = '1' align = 'left'><font size='2'font color = '#ffffff' face='Arial'>$pdf_id</td>";

//echo  "<td width = '150' height = '1' align = 'left' ><font size='2'font color = '#ffffff' face='Arial'>$date</td>";

echo "</tr>";

} 








?>





</table>
<br clear = "left"/>
</p16>




       

            <?php

            if ($rows>10){
				            ?>

            <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">

           <tr>

            <td><hr noshade color="#FFFFFF" align="left" width="100%" size="2"> </td>

          </tr>

          <tr>

            <td align="center">
<p23>
            <?php

                              

              include('paging2.php');

            ?>

           </td>

          </tr>

          </table><br>

           <?php } ?>


 

Can anyone see where I'm going wrong?

 

Cheers

 

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.