Jump to content

Pagination


doddsey_65

Recommended Posts

Okay here is the page in question: http://blenderteachings.000a.biz/tutorials.hamishhill.php

 

I have the records in a database(tutorial name, username description etc). I am pulling these and displaying them but i need them to be set out like this http://blenderteachings.000a.biz/index.php

 

But my code doesnt do it like that. Any ideas?

 

Heres the code:

 

<?php 

ob_start();
include('header.php'); 
include('db.php');
    $db=mysql_connect($db_host,$db_user,$db_pass)
or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db($db_name,$db);

if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 


$data = mysql_query("SELECT * FROM tutorials") or die(mysql_error()); 
$rows = mysql_num_rows($data); 

$page_rows = 3; 

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

if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;


$sql = "SELECT username, fullname, description, link
        FROM   tutorials
        WHERE  username='hamsterhill' $max";

$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>

<div id="page">
<div id="content"><br>
<div class="post">
<p class="meta"><?php echo $row["fullname"] . ' | ' .$row["username"]; ?>
<img src="images/img08.png" alt="bullet"></p>

	<div class="entry">			
	<?php echo $row['description']; echo '<br />'; } ?>
	</div>
</div>   

<?php
echo " Page $pagenum of $last <p>";

if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
} 


//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']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
} 
?>
</div>

<?php include('footer.php');
ob_flush(); 
mysql_close($db);
?>

Link to comment
Share on other sites

Okay i got the format to work but when i click next page it just shows up the same results not the next ones.

 

<?php 

ob_start();
include('header.php'); 
include('db.php');
    $db=mysql_connect($db_host,$db_user,$db_pass)
or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db($db_name,$db);
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 


$data = mysql_query("SELECT * FROM tutorials") or die(mysql_error()); 
$rows = mysql_num_rows($data); 

$page_rows = 3; 

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

if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

echo '<div id="page">';
echo '<div id="content"><br />';
echo '<h2 class="title">Tutorials By Hamish Hill</h2><br />';

$sql = "SELECT name, fullname, description, link, path
        FROM   tutorials
        WHERE  username='hamsterhill' $max";

$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {


echo '<div class="post">';
echo '<p class="meta">' .$row["fullname"]. ' | ' .$row["name"]. '<img 

src="images/img08.png" alt="bullet"></p>';

echo '<div class="entry">';			
echo '<p><img src=' .$row['path']. ' hspace=10 align=left>';
echo $row['description']. '</p>'; 
echo '</div>';
echo '</div>';

} 

echo "<p> Page $pagenum of $last </p>";

if ($pagenum == 1) 
{
} 
else 
{
echo " <p><a href='{$_SERVER['PHP_SELF']}?pagenum=1' class=links> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous' class=links> <-Previous</a> 

</p>";
} 

if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <p><a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class=links>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last' class=links>Last ->></a></p> ";

}
echo '</div>';


include('footer.php');
ob_flush(); 
?>

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.