Jump to content

issue with next and prev page


wmguk

Recommended Posts

hey,

 

I currently use this script to generate a thumbnail, it just looks at all the files and then displays them, but i was wondering if there is anyway to make it display 10 images at a time, and have a prev and next?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$dir = $_GET['login'];
    $login = $_GET['login'];	
$pricing = $_GET['pricing'];
$user = $_GET['user'];
$counters = $_GET['counters'];
$accessdetail = $_GET['accessdetail'];
    $NBFile=0;
    $dir ="../../clients/$dir";
$todate = date('Y-m-d H:i:u');

//RUN UPDATE COUNTERS & ACCESS DETAILS
include '../scripts/connection.php';
if (!$con)
  {
  die('Could not connect: ' . mysql_error() );
  }
  mysql_select_db($db, $con);

//Run the update query
$sql="UPDATE album SET counters = '$counters' , accessdetail = '$todate' WHERE login='$login'" ;


  mysql_query( $sql , $con ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); 
//Close the connection
  mysql_close($con);


if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
	   $namearray[] = $file;
           $FileArray[] = $dir."/".$file;
            $NBFile=$NBFile+1;
        }
    }
}
closedir($handle);
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.image{
border-style:outset;
border-color: black;
border-width:1px;
      }
</style>
</head>
<body
<table align="center"><tr>
<?php
$NBPicswidth=1;
$NBPics=0;
for ($i=0; $i<$NBFile; $i++) {
$Pic_Name1=$FileArray[$i];
$Name=$namearray[$i];
?><td class="image">
  <a href="dis.php?image=<?php echo $Pic_Name1; ?>&pricing=<?php echo $pricing; ?>&loginname=<?php echo $login; ?>&name=<?php echo $Name; ?>&user=<?php echo $user; ?>" target="order"><img src="<?php echo $Pic_Name1; ?>" width="100" border="0" align="top"></a>
  </td></tr>
  <?php
$NBPics=$NBPics+1;

if ( $NBPics==$NBPicswidth ) { $NBPics=0; ?>
<?php }
}
?></table>
</body>
</html>

Link to comment
Share on other sites

$limit=10; 


$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["1st_field"];

echo "$count.) $title" ;
$count++ ;
}

$currPage = (($s/$limit) + 1);

//break before paging
echo "<br />";

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>&nbsp ";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;

echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";

?>

 

try that some code I write for a old site

Link to comment
Share on other sites

Thank you for that, that looks like its supposed to connect to a db, but these images are all just held in a standard folder, will this still work?

 

$limit=10; 


$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["1st_field"];

echo "$count.) $title" ;
$count++ ;
}

$currPage = (($s/$limit) + 1);

//break before paging
echo "<br />";

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>&nbsp ";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;

echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";

?>

 

try that some code I write for a old site

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.