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
Run function every 5 mins ??
I have a function PostMessage()
How can I run it every 5 mins ??
Add a sign-up feature to a flat file login script
I'm working on a flat file login script and I would like to add a sign-up feature to it with a email
Syntax Help
I'm trying to make a form that edits a php file which contains config settings. I'm using strings t
reading xml faster than DB call?
I am trying to optimize a high traffic website, and I enabled a feature where there are three photos
how do I show what a user have selected from a checkbox?
From my code below, how would i show which check boxes have been checked and which radio buttons sel
New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code righ
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
what is wrong with this
Code: [Select]<?php
if ($_SERVER['HTTP_REFERER'])
{
Socket problem
Hello,
Earlier I posted about my problem with my socket script. It took up to 100% CPU usage.
need to add "sizes" to shopping cart
Hey guys, I am trying to figure out a way to add a "size" selector on to this bit of code.
Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi