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

Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to

Function module "DPS_CHECK_TABLE_EXISTS" not found (after OSS 1422843 impl)
Dear All,

I implemented Note OSS 1422843.

When i execute the new report RSPO20

PHP & Java
Hello,

can PHP code be used inside java code?

Code: <SCRIPT LANGUAGE="Java

1,000 select boxes with 100 options?!
I have 1 drop down select box with 1,000 options.


In some case, there will be 100+ of the

PHP search multiple input field box help
I am having a problem with my search script. At current it will simply search by a selected date whi

SAP Logon Failed
I tried to login to SAP through MMC.

When i click start and give password.

it

PHP Script runs on CLI but not through web browser
I am running into an issue that I just can't seem to find the answer to. I have a Windows Server 200

Linked Keywords
I am trying to get a script that makes my predefined keyword converted to links and / or converted t

having a small php error tha deals with the 'foreach'
Last night i was working on a script for a cart and it seemed to working good, until this morning. F

How to make a input/output field with multiple lines
Hello.
I put a input/output field on the screen but I could not change height of it. I need to

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