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?

347 Like 43 Dislike
Previous php-forum Next php-forum
Other php-forum

Staff Induction System - No idea where to go from here!!!
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi

how can i make a .gif images for my site
Dear Friends ,

Pls solve my problem , I am starting making new site but i dont know how can i

Sessions work for me and not others?
I'm having a bit of bad luck with sessions. In the past they have worked fine for me, but this time

a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header error

I'm do not know php &

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com

How to alter the scri

Writing to the middle of a file
Hi I have a bit of a problem. Is there any way i can write some text to a middle of a text file. For

PHP Captcha Error help - replace the "die" command
Hi All,

I am after a bit of help with a Captcha spam protection box.

The site gave me

the problem with str_replace
$str="hahahahahahahahahahahahahaha";
$nn=1;
$str=str_replace('ha','MyGod',$str,$nn);

If a form submits back to same page do you need to use $get
IM trying to pass page number and year that was selected back to the same page.

i have this c

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