pageination not working right... coping images over 4 pages
Posted on
16th Feb 2014 07:03 pm by
admin
Code: <?php //This code will obtain the required page number from the $_GET array. Note that if it is not present it will default to 1.
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
//This code will count how many rows will satisfy the current query.
$query ="SELECT * FROM `photos` WHERE `thumb_id` = '3'";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
//This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page.
$rows_per_page = 3;
$lastpage = ceil($numrows/$rows_per_page);
//This code checks that the value of $pageno is an integer between 1 and $lastpage.
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
//This code will construct the LIMIT clause for the sql SELECT statement.
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
//Now we can issue the database qery and process the result.
$sql="SELECT * FROM `photos` WHERE `thumb_id` = '3'";
$res = mysql_query($sql) or die(mysql_error());
echo "<table>";
$i = 0;
while($row = mysql_fetch_assoc($res)){
$i++;
if ($i % 3 == 0)
echo '<tr>';
echo "<td> <img src="http://www.runningprofiles.com/members/include/myimages/thumbs/" . $row['picurl'] . "" /></a><br /> </td>";
if ($i % 3 == 0)
echo '</tr>';
if( $i == 9 ) break;
}
echo "</table>";
//... process contents of $result ...
//Finally we must construct the hyperlinks which will allow the user to select other pages. We will start with the links for any previous pages.
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='http://www.runningprofiles.com/members/index.php?page=album&pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='http://www.runningprofiles.com/members/index.php?page=album&pageno=$prevpage'>PREV</a> ";
} // if
//Next we inform the user of his current position in the sequence of available pages.
echo " ( Page $pageno of $lastpage ) ";
//This code will provide the links for any following pages.
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='http://www.runningprofiles.com/members/index.php?page=album&pageno=$nextpage'>NEXT</a> ";
echo " <a href='http://www.runningprofiles.com/members/index.php?page=album&pageno=$lastpage'>LAST</a> ";
} // if
?>
Im alittle confused by my pageinated results... i only have 2 images... and for some reason its repeated these images over 11 pages... how comes?
No comments posted yet
Your Answer:
Login to answer
347 43
Other forums
modifying query string with no page refresh
Hi everybody,
I've tried to get info about my problem all over the internet but i didn't find out
Scrolling news bar and MySQL
I am not sure if this is the correct forum to post this on. If not, I apologize. I am still pretty
Time-based image rotation script
I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the
Call db table from any PHP file
Hi,
I want to be able to call a database table that will be setup in another file called init
MSSQL/PHP
I am tryint to setup a webapplication developed in PHP, Apache2.0 and SQLServer2000 as backend which
Greek characters in php
Hi,
I'm making a script and I m using for first time greek characters.
I started to write
HOW to get the bind variables list.
I've the following problem : I've some SQL queries stored in my DB as VARCHAR2 values.
I need t
Character Set Setup
Whats the best character set to use if you want every character to work, and also how do you make yo
ob_ dynamic content
i was wondering about the potential to use ob to create a <div then remove it when the page
mr8m - reverse document
Friends,
I'm trying to reverse a document held by MIRO, but it reports the message balan