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
Echo multiple lines of html code
Hi guys,
I would like to know if there is a way to echo multiple lines of html codes.
for some reason mysql query not working, not inserting, please check it out
This code is not inserting anything into my db, don't know why, the $_SESSION variable does contain
simple script won't work. Please help
I'm new to php, and I am having trouble displaying a simple script in my web browser. My php code ex
textfield unchanged
hi,
i want my form to know whether its textbox is unchange or not.
if($textbox == 'unchang
Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter
Confusing Functions
So, I've been reading up on Functions and I like them! However, I need some help using variables in
Need to write a cookie with a url var
Not sure if its possible, but I need to write a cookie with a url.
So this would write 2232 a
shoping cart issues
i´ve wrote this and works when i add an item to, my cart, but when i want to add othrer item just
Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data
question about header() security
is is safe to just use the header() function to redirect someone if they are, say, not logged in? or