Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 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 Search this Thread Display Modes
  #1 (permalink)  
Old March 10th, 2008, 06:44 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paginate function with thumbnails

 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:
    <?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:
    <?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\">< PREV</span>";
        }else{
          $pageprev = $page - 1;
          $pagelinks .= "<a class=\"pageprevlink\" href=\"" . $currpage .
                        "&page=" . $pageprev . "\">< 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 .= " ";
        }
        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 .= " ";
        }

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


    ?>



displaying error on browser....

    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:
    <?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
* sorry for the double posting in other section (beginner)

Reply With Quote
  #2 (permalink)  
Old March 13th, 2008, 07:52 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you need to change the syntax on sql statement so that the variables are outside the quotes and the commas are inside quotes.

Try changing sql statement as follows in gallery.php and let me know if this addresses some of the variable not found errors:

    $sql = "SELECT SQL_CALC_FOUND_ROWS " .
        $ImageDir . ", " .
        $image_id . ", " .
        $ImageThumb . ", " .
        $image_caption . ", " .
        $image_description . ", " .
        $image_date . " " .
        "FROM images " .
        "LIMIT $start, $limit";

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Paginate function with thumbnails, chpter 7 and 16 dragon_rouge Beginning PHP 0 March 10th, 2008 06:26 AM
Paginate xml data solos Classic ASP XML 0 April 4th, 2007 01:57 AM
chapter 7, THUMBNAILS r4n34 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 November 24th, 2006 09:26 PM
paginate Neeko C++ Programming 1 March 8th, 2006 03:33 PM
thumbnails without gd library? cutesneakers PHP How-To 1 January 14th, 2005 05:34 AM



All times are GMT -4. The time now is 06:21 PM.


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