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)