$ 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 andJerry, I''ve ended up with an image gallery on my website that displaysimages in a table, 3 images per row. This works great and opens all imagesin the database when I open the url mywebsite/gallery.php, or I can choosecertain images (by category) by going to url''s likemywebsite/gallery.php?category=landscape Although the above worked perfectly with 15 images in the database, I''verealised that as I add more images to the database (I will probably have afew hundred images in total before long), I''m going to need to sort out thegallery pages so that instead of displaying, say, 100 images in a big longpage, 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 codewhich 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 smallproblem. The pagination now works when I go to mywebsite/gallery.php andit''s great. However, when I go to mygallery/gallery.php?category=landscape,instead of showing the paginated Landscape gallery, it instead shows allimages from the database in paginated format, which is basically the same asthe mywebsite/gallery.php page In adding the above pagination code, I''ve somehow messed something up whenwanting 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 <?phpinclude("databasepasswords"); $connection = mysql_connect($host,$user,$password) or die ("couldn''tconnect to server");$db = mysql_select_db($database,$connection) or die ("Couldn''t selectdatabase"); 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\"><ahref=\"/image_viewer.php?imageid=".$row[''imageid'']."\"><imgsrc=\"/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, 这篇关于画廊分页结果问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 04:51