Pagination


Posted on 16th Feb 2014 07:03 pm by admin

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:

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">

<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);
?>

No comments posted yet

Your Answer:

Login to answer
300 Like 51 Dislike
Previous forums Next forums
Other forums

utl_file open error
i have file in the unix path

Path /popdev01/pop/popdevb/tfi/

File name

What's wrong with my code
sobbing for many days, still don't know why please Help. Why my page isn't posted correctly. In a

php + mysql count consecutive data
I have a database of values and I want to work out how to display them if the values match a consecu

comparing tables across databases sql refinement ideas required
Hi all

Via pl/sql I need to ensure that data between tables in different databases match

This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the

extract data
Code: <div class="post hentry uncustomized-post-template">

Odd or Even
Inside of a while loop I need to echo several rows of info...easy enough.

In the loop (for th

writing a screen scraper
Hello,

I'm writing a screen scraper application and want to be able to get absolute addresses

ctype() validation - allowing illegal characters
Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain c

Select all entries from database that include a phrase
I have a database of clubs - one of the categories is meeting time and place
I would like to have

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash