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 Like 43 Dislike
Previous forums Next forums
Other forums

b+ tree
Hi
can every body help me about b+ tree ?(insert & delete)

Procedure with variable number of columns
Hi, I have a procedure that looks like this:

PROCEDURE PROC(p_cursor OUT sys_refcurso

Help Import Animoto and Youtube
CAn someone help me urgently want to allow users on my website to import youtube/revver/dailymotion

Database 'Validation'
Hi everyone,
I'm trying to validate the password entered by the user with the password in the dat

help connecting a form to php and then emailing the form
Ok. So, I made a form, and I need help to where when submitted, I get an email with the submitted de

IS Retail & Manufacturing
Hi

Can IS Retail and Manufacturing activities be done in same instance ie. in same client

Can't find the problem (no error message)!
OK, here's the deal. This code is really weirdly formatted (sorry!) and hard to understand, so I'm g

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

Header is not working in IE
Hi ! header function is not working in IE but it works in FF, Safari, Chrome. any help please. :

how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass

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