Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 10th, 2008, 06:26 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paginate function with thumbnails, chpter 7 and 16

hello.
thanks wrox for the excellent book (beginning php5) and this forum.
So here his my question about a function paginate (chapter 16) that i'm trying to put with the tumbnail gallery (chapter 7).
After some trials i don't still be able to put it all together. Some advices from you fellas would be precious to understand the paginate() function.

gallery.php
Quote:
quote:
<?php
require_once 'functions.php';

$page = 1;
$limit = 4;
$start = ($page - 1) * $limit;


//connect to the database
$link = mysql_connect("localhost", "root", "password")
  or die("Could not connect: " . msql_error());
mysql_select_db("dados", $link)
  or die (mysql_error());

$ImageDir = "images/";
$ImageThumb = $ImageDir . "thumbs/";
?>

<html>
<head>
<title>Welcome to our Photo Gallery</title>
</head>
<body>
<p align="center">Click on any image to see it full sized.</p>
<table align="center">
  <tr>
    <td align="center">Image</td>
    <td align="center">Caption</td>
    <td align="center">Uploaded By</td>
    <td align="center">Date Uploaded</td>
  </tr>

<?php
//get the thumbs

$sql = "SELECT SQL_CALC_FOUND_ROWS " .
    "$ImageDir, " .
    "$image_id, " .
    "$ImageThumb, " .
    "$image_caption, " .
    "$image_description, " .
    "$image_date, " .
    "FROM images " .
    "LIMIT $start, $limit";
$getpic = mysql_query($sql)
  or die(mysql_error() . $sql);
$pagelinks = paginate($limit);


//$getpic = mysql_query("SELECT * FROM images")
// or die(mysql_error());
while ($rows = mysql_fetch_array($getpic)) {
  extract($rows);
  echo "<tr>\n";
  echo "<td><a href=\"".$ImageDir . $image_id . ".jpg\">";
  echo "<img src=\"" . $ImageThumb . $image_id . ".jpg\" border=\"0\">";
  echo "</a></td>\n";
  echo "<td>" . $image_caption . "</td>\n";
  echo "<td>" . $image_description . "</td>\n";
  echo "<td>" . $image_date . "</td>\n";
  echo "</tr>\n";
  }
  echo paginate();
?>

</table>
</body>
</html>
function.php
Quote:
quote:
<?php
function paginate($limit=4) {
  global $admin;

  $sql = "SELECT FOUND_ROWS();";
  $result = mysql_query($sql)
    or die(mysql_error());
  $row = mysql_fetch_array($result);
  $numrows = $row[0];
  $pagelinks = "<div class=\"pagelinks\">";
  if ($numrows > $limit) {
    if(isset($_GET['page'])){
      $page = $_GET['page'];
    } else {
      $page = 1;
    }
    $currpage = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
    $currpage = str_replace("&page=".$page,"",$currpage);

    if($page == 1){
      $pagelinks .= "<span class=\"pageprevdead\">&lt; PREV</span>";
    }else{
      $pageprev = $page - 1;
      $pagelinks .= "<a class=\"pageprevlink\" href=\"" . $currpage .
                    "&page=" . $pageprev . "\">&lt; PREV</a>";
    }

    $numofpages = ceil($numrows / $limit);
    $range = $admin['pageRange']['value'];
    if ($range == "" or $range == 0) $range = 7;
    $lrange = max(1,$page-(($range-1)/2));
    $rrange = min($numofpages,$page+(($range-1)/2));
    if (($rrange - $lrange) < ($range - 1)) {
      if ($lrange == 1) {
        $rrange = min($lrange + ($range-1), $numofpages);
      } else {
        $lrange = max($rrange - ($range-1), 0);
      }
    }

    if ($lrange > 1) {
      $pagelinks .= "..";
    } else {
      $pagelinks .= "&nbsp;&nbsp;";
    }
    for($i = 1; $i <= $numofpages; $i++){
      if ($i == $page) {
        $pagelinks .= "<span class=\"pagenumdead\">$i</span>";
      } else {
        if ($lrange <= $i and $i <= $rrange) {
          $pagelinks .= "<a class=\"pagenumlink\" " .
                        "href=\"" . $currpage . "&page=" . $i .
                        "\">" . $i . "</a>";
        }
      }
    }
    if ($rrange < $numofpages) {
      $pagelinks .= "..";
    } else {
      $pagelinks .= "&nbsp;&nbsp;";
    }

    if(($numrows - ($limit * $page)) > 0){
      $pagenext = $page + 1;
      $pagelinks .= "<a class=\"pagenextlink\" href=\"" . $currpage .
                    "&page=" . $pagenext . "\">NEXT &gt;</a>";
    } else {
      $pagelinks .= "<span class=\"pagenextdead\">NEXT &gt;</span>";
    }
  } else {
    $pagelinks .= "<span class=\"pageprevdead\">&lt; " .
                  "PREV</span>&nbsp;&nbsp;";
    $pagelinks .= "<span class=\"pagenextdead\"> " .
                  "NEXT &gt;</span>&nbsp;&nbsp;";
  }
  $pagelinks .= "</div>";
  return $pagelinks;
}


?>
displaying error on browser....:(

Quote:
quote:
Click on any image to see it full sized.

Notice: Undefined variable: image_id in c:\program files\easyphp18\www\gallery.php on line 39

Notice: Undefined variable: image_caption in c:\program files\easyphp18\www\gallery.php on line 41

Notice: Undefined variable: image_description in c:\program files\easyphp18\www\gallery.php on line 42

Notice: Undefined variable: image_date in c:\program files\easyphp18\www\gallery.php on line 43
Erreur de syntaxe près de ' , images/thumbs/, , , , FROM images LIMIT 0, 4' à la ligne 1SELECT SQL_CALC_FOUND_ROWS images/, , images/thumbs/, , , , FROM images LIMIT 0, 4
Image Caption Uploaded By Date Uploaded

i've tried also a simple query "SELECT * FROM images LIMIT $page, $limit"

Quote:
quote:
<?php
require_once 'functions.php';

$page = 1;
$limit = 4;
$start = ($page - 1) * $limit;

//$start = ($page - 1) * $admin['pageLimit']['value'];
//connect to the database
$link = mysql_connect("localhost", "root", "password")
  or die("Could not connect: " . msql_error());
mysql_select_db("dados", $link)
  or die (mysql_error());

$ImageDir = "images/";
$ImageThumb = $ImageDir . "thumbs/";
?>

.......
........
<?php
//get the thumbs


$getpic = mysql_query("SELECT * FROM images LIMIT $page, $limit")
  or die(mysql_error());
while ($rows = mysql_fetch_array($getpic)) {
  extract($rows);
  echo "<tr>\n";
  echo "<td><a href=\"".$ImageDir . $image_id . ".jpg\">";
  echo "<img src=\"" . $ImageThumb . $image_id . ".jpg\" border=\"0\">";
  echo "</a></td>\n";
  echo "<td>" . $image_caption . "</td>\n";
  echo "<td>" . $image_description . "</td>\n";
  echo "<td>" . $image_date . "</td>\n";
  echo "</tr>\n";
  }
  echo paginate();
?>
partially works, no error display but don't still be able to navigate trough pages (always displays the same..)



in advance thanks for your opinions and advices,
best regards
josef


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16 Fig 16-11 krsouthern BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 12:11 PM
Paginate function with thumbnails dragon_rouge BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 13th, 2008 07:52 PM
Paginate xml data solos Classic ASP XML 0 April 4th, 2007 01:57 AM
paginate Neeko C++ Programming 1 March 8th, 2006 02:33 PM
Error with Struts example -Chpter 15 -Please help PatrickWalsh JSP Basics 0 March 18th, 2004 08:54 PM



All times are GMT -4. The time now is 09:21 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.