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
51
Other forums
Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u
using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a ga
preg-match with a string and numbers
Hi, I can't get the expression to work for my preg_match, what I'd like is for it to match the strin
Get to know your fellow coder
I think it's time we got personal around here. There's a lot of code swapping and a few members kno
date function help
i need help with date function
Code: [Select]<!DOCTYPE HTML PUBLIC "-//W3C//DTD H
How to separate records and ORDER BY
Let say i have 100 records and displayed in one page, then i want to get the records from 50-100 and
trim function issues
Hi guys, total noob here...
So I've been tinkering around with a html and am using php to em
How to get all server headers like Live http Headers does
Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res