画廊分页结果问题 [英] Gallery Pagination Result Problem

查看:77
本文介绍了画廊分页结果问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


继我最近的帖子里,我得到了Rik的优秀帮助和

Jerry,我结束了在我的网站上有一个图像库,在一个表格中显示

图像,每行3个图像。当我打开url mywebsite / gallery.php时,这很好用并打开数据库中的所有图像

,或者我可以选择

某些图像(按类别) url'喜欢

mywebsite / gallery.php?category = landscape


虽然以上内容与数据库中的15张图片完美配合,但我已经

意识到,当我向数据库中添加更多图像时(不久我可能会有几百张图片),我将需要排序超出

画廊页面,而不是在一个很长的

页面中显示100个图像,而是每页显示12个图像,然后链接到Next ,

上一个,第一个,最后一个等等


花了一个小时进行谷歌搜索后,我找到了一些代码

从本网站教程中分页:
HTTP://瓦特ww.tonymarston.co.uk/php-mysql/pagination.html


我已将此代码插入到我现有的代码中,但遇到了一个小的

问题。当我访问mywebsite / gallery.php并且

时,分页现在很有效。但是,当我去mygallery / gallery.php?category = landscape,

而不是显示分页的Landscape库时,它会在分页中显示数据库中的所有

图像格式,这与

mywebsite / gallery.php页面基本相同


添加上面的分页代码,我在某种程度上搞砸了什么

想要根据类别打开画廊。我复制了下面的代码 -

任何人都可以看到任何明显我做错了吗?通过反复试验,

我试图调整代码中的查询,但无济于事。


感谢您的帮助,


Stephen


<?php

include(databasepasswords);

$ connection = mysql_connect($ host,$ user,$ password)或死亡(无法连接到服务器的
);

$ db = mysql_select_db($ database,$ connection)或死(无法选择

数据库);


if(isset($) _GET [''pageno''])){

$ pageno = $ _GET [''pageno''];

}其他{

$ pageno = 1;

} //如果


$ query =" SELECT count(*)FROM images"。$ where;

$ result = mysql_query($ query)或trigger_error(" SQL",E_USER_ERROR);

$ query_data = mysql_fetch_row($ result);

$ numrows = $ query_data [0];


$ rows_per_page = 12;

$ lastpage = ceil($ num rows / $ rows_per_page);


$ pageno =(int)$ pageno;

if($ pageno< 1){

$ pageno = 1;

} elseif($ pageno> $ lastpage){

$ pageno = $ lastpage;

} //如果


$ limit =''LIMIT''。($ pageno - 1)* $ rows_per_page。'',''。$ rows_per_page ;

$ query =" SELECT * FROM images ORDER BY dateadded,datetaken DESC $ limit

"。$ where;

$ result = mysql_query($ query)或trigger_error(" SQL",E_USER_ERROR);


if(get_magic_quotes_gpc()){

$ _GET [''category ''] = stripslashes($ _ GET [''category'']);

}

$ category = mysql_real_escape_string($ _GET [''category''],$连接);

$ category = ucfirst($ category);

$ where =(isset($ _ GET [''category''])&& $ _ GET [''category'']!='''')? WHERE类别

=''"。$ category。"''":'''';

$ result = mysql_query($ query)或死(无法执行查询。);


echo" \ n< div id = \" content \">" ;

echo" \ n< h2> $ category Gallery< / h2>" ;;


if($ pageno == 1){

echo FIRST PREV" ;;

}否则{

echo" < a href =''{$ _ SERVER [''PHP_SELF'']}?pageno = 1''> FIRST< / a> " ;;

$ prevpage = $ pageno-1;

echo" < a href =''{$ _ SERVER [''PHP_SELF'']}?pageno = $ prevpage''> PREV< / a> ;

} //如果


echo (页面$ pageno of $ lastpage)" ;;


if($ pageno == $ lastpage){

echo"下一个< ;;

}其他{

$ nextpage = $ pageno + 1;

echo" < a href =''{$ _ SERVER [''PHP_SELF'']}?pageno = $ nextpage''> NEXT< / a> " ;;

echo" < a href =''{$ _ SERVER [''PHP_SELF'']}?pageno = $ lastpage''> LAST< / a> ;

} //如果


echo" \ n< table id = \" thumbgallery \" CELLSPACING = \" 0\" cellPadding = \" 10 \"

width = \" 400 \" border = \" 0 \">" ;;

echo" \ n< tbody>" ;;

$ i = 3;

while($ row = mysql_fetch_assoc($ result))

{

if($ i == 3)echo" \ nn \\ t< tr>" ;;

echo" \ n\t\t< td valign = \" top \"宽度= \" 113\" id = \" thumbs \"

align = \" center \">< a

href = \" / image_viewer.php?imageid ="。$ row [''imageid'']。" \">< img

src = \" / images / gallery / t" ; $行[ '' 图像标识 '']"。.jpg\" border = \" 0 \"

alt = \""。$ row [''caption'']。" \" />< / a>< p class = \" captionref \"> Ref:

"。$ row [''imageid'']。"< ; / p>< p class = \" caption \">"。$ row [''caption'']。"< / p>< / td>" ;;

$ i - ;

if($ i == 0){

echo" \ n\t< tr>" ;

$ i = 3;

}

}

if($ i!= 3)echo ; \\\\\&< td colspan = \" $ i \">< / td> \ n \ t< / tr>" ;;

echo" \ n< / tbody>" ;;

echo" \ n< / table>" ;;


?> ;

解决方案

connection = mysql_connect(


host,


用户,

Hi there,

Further to my recent posts where I''ve received excellent help from Rik and
Jerry, I''ve ended up with an image gallery on my website that displays
images in a table, 3 images per row. This works great and opens all images
in the database when I open the url mywebsite/gallery.php, or I can choose
certain images (by category) by going to url''s like
mywebsite/gallery.php?category=landscape

Although the above worked perfectly with 15 images in the database, I''ve
realised that as I add more images to the database (I will probably have a
few hundred images in total before long), I''m going to need to sort out the
gallery pages so that instead of displaying, say, 100 images in a big long
page, it instead displays 12 images per page, and then has links to Next,
Previous, First, Last, etc.

After spending an hour going through Google searches, I''ve found some code
which enables pagination from this website tutorial:
http://www.tonymarston.co.uk/php-mysql/pagination.html

I''ve inserted this code into my existing code, yet have came across a small
problem. The pagination now works when I go to mywebsite/gallery.php and
it''s great. However, when I go to mygallery/gallery.php?category=landscape,
instead of showing the paginated Landscape gallery, it instead shows all
images from the database in paginated format, which is basically the same as
the mywebsite/gallery.php page

In adding the above pagination code, I''ve somehow messed something up when
wanting to open galleries based on categories. I''ve copied the code below -
can anyone see anything obvious I''ve done wrong? Through trial and error,
I''ve tried to adjust the queries in the code, but to no avail.

Thanks for any help,

Stephen

<?php
include("databasepasswords");

$connection = mysql_connect($host,$user,$password) or die ("couldn''t
connect to server");
$db = mysql_select_db($database,$connection) or die ("Couldn''t select
database");

if (isset($_GET[''pageno''])) {
$pageno = $_GET[''pageno''];
} else {
$pageno = 1;
} // if

$query = "SELECT count(*) FROM images ".$where;
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} // if

$limit = ''LIMIT '' .($pageno - 1) * $rows_per_page .'','' .$rows_per_page;
$query = "SELECT * FROM images ORDER BY dateadded, datetaken DESC $limit
".$where ;
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

if(get_magic_quotes_gpc()){
$_GET[''category''] = stripslashes($_GET[''category'']);
}
$category = mysql_real_escape_string( $_GET[''category''], $connection);
$category = ucfirst($category);
$where = (isset($_GET[''category''])&&$_GET[''category'']!='''') ? "WHERE category
= ''".$category."''":'''';
$result = mysql_query($query) or die ("Couldn''t execute query.");

echo "\n<div id=\"content\">";
echo "\n<h2>$category Gallery</h2>";

if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href=''{$_SERVER[''PHP_SELF'']}?pageno=1''>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href=''{$_SERVER[''PHP_SELF'']}?pageno=$prevpage''>PREV</a> ";
} // if

echo " ( Page $pageno of $lastpage ) ";

if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href=''{$_SERVER[''PHP_SELF'']}?pageno=$nextpage''>NEXT</a> ";
echo " <a href=''{$_SERVER[''PHP_SELF'']}?pageno=$lastpage''>LAST</a> ";
} // if

echo "\n<table id=\"thumbgallery\" cellSpacing=\"0\" cellPadding=\"10\"
width=\"400\" border=\"0\">";
echo "\n<tbody>";
$i = 3;
while ($row = mysql_fetch_assoc($result))
{
if($i==3) echo "\n\t<tr>";
echo "\n\t\t<td valign=\"top\" width=\"113\" id=\"thumbs\"
align=\"center\"><a
href=\"/image_viewer.php?imageid=".$row[''imageid'']."\"><img
src=\"/images/gallery/t".$row[''imageid''].".jpg\" border=\"0\"
alt=\"".$row[''caption'']."\" /></a><p class=\"captionref\">Ref:
".$row[''imageid'']."</p><p class=\"caption\">".$row[''caption'']."</p></td>";
$i--;
if($i==0) {
echo "\n\t<tr>";
$i = 3;
}
}
if($i!=3) echo "\n\t\t<td colspan=\"$i\"></td>\n\t</tr>";
echo "\n</tbody>";
echo "\n</table>";

?>

解决方案

connection = mysql_connect(


host,


user,


这篇关于画廊分页结果问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆