473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pagination in category

14
Hello,
I have a page whit categories. The problem that I'm facing is how to make pagination in the category? When I click for exaple 'Autos' and open images only from 'Autos' how to change next image from this category?

I have this so far but when I load category the page is blank.
Expand|Select|Wrap|Line Numbers
  1. $cat_id = $_GET['cat_id'];
  2.             $cat_id = mysqli_real_escape_string($con, $cat_id);
  3.             $query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'";
  4.             $result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
  5.             if (isset ($_GET['id'])) {
  6.                 $id = $_GET['id'];
  7.             $prevSQL = mysqli_query($con,"SELECT id FROM images WHERE id < $id ORDER BY id DESC LIMIT 1") or die (mysqli_error($con));
  8.             $nextSQL = mysqli_query($con, "SELECT id FROM images WHERE id > $id ORDER BY id ASC LIMIT 1") or die (mysqli_error($con));
  9.             $prevobj=mysqli_fetch_object($prevSQL);
  10.             $nextobj=mysqli_fetch_object($nextSQL);
  11.             $pc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(id) as pid FROM images WHERE id<$id ORDER BY id DESC")) or die (mysqli_error($con));
  12.             $nc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(id) as nid FROM images WHERE id>$id ORDER BY id ASC")) or die (mysqli_error($con));
  13.             $prev=$pc->pid>0 ? '<a href="pic.php?cat_id='.$cat_id.'&id='.$prevobj->id.'">Prev</a> |' : '';
  14.             $next=$nc->nid>0 ? '<a href="pic.php?cat_id='.$cat_id.'&id='.$nextobj->id.'">Next</a>' : '';
  15.  
  16.  
  17.             $row = mysqli_fetch_array($result);
  18.             echo "<div id=\"picture\">";
  19.             echo "<img src=\"upload/" . $row['name']  . "\" alt=\"\" /><br />";
  20.             echo $row['caption'] . "<br />";
  21.             echo "</p>";
  22.             echo $prev;
  23.             echo $next;
  24.  
  25. echo '</div>';
  26.             }
Feb 9 '14 #1
0 1119

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
by: ste | last post by:
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. ...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
1
by: Alec | last post by:
Newbie question. I have recently tried a php tutorial on pagination, but I just cannot get the links to work. See www.freeweekends.co.uk/pagtest2.php. The search finds over 60 results, but only...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
1
by: vinpkl | last post by:
hi all i m using pagination to show my products results according to particular category. it shows PREV 1,2, NEXT but when i click these links then these links dont show next and prev...
15
omerbutt
by: omerbutt | last post by:
hi i have made a simple pagination but it is creating problem , the problem is that if there are any products under the category that is clicked in the left menu then the page works fine but if it...
1
by: rienh | last post by:
I'am using Adam's pagination script from: http://www.developphp.com/view_lesson.php?v=289 And I adjusted the code just a little, so it fitted my needs. Now I bumb into a problem, and I can't figure...
1
by: alimziyan | last post by:
Hi, I am new to joomla component development.Now i am creating a simple image gallery.I have created it sucessfully in joomla1.6. But a small pagination problem while using it in joomla 1.7.The...
0
by: ROXIT | last post by:
Here i am collecting the category and area value from the search-form using get method.so as i m having a 7 records into the database and i want to display only 4 records per page and when user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.