473,396 Members | 2,036 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,396 software developers and data experts.

How to make Next and Prev buttons to work

14
Hi,
still learning and I trying to make buttons for Next and Prev.
So far I can pull the image from database and show in the page but buttons doesn't work. When I click on Next or Prev it's just reload the page with the same image.
Can someone help me with this?
Here is the code
Expand|Select|Wrap|Line Numbers
  1.             if($q = mysqli_query($con, "SELECT * FROM images WHERE `name` = '". preg_replace('/[^.A-Za-z0-9]/ui', '',  $_GET['name']) ."' LIMIT 1")) {
  2.                 if($row = mysqli_fetch_array($q)){
  3.                     echo '<a href="pic.php?name='.$row['name'].'" class="button button-blue"><span>Prev</span></a>';
  4.                     echo '<a href="pic.php?name='.$row['name'].'" class="button_next button-blue"><span>Next</span> </a>';
  5.                     echo "<img style=\"width:100%;margin:0 auto;\" src=\"upload/".$row['name']."\" />";
  6.  
  7.                 } else {
  8.                     echo 'Not found';
  9.                 }
  10.             } else {
  11.                 echo mysqli_error($con);
  12.             }
Jan 25 '14 #1

✓ answered by Atli

Yes, if you want to go with the name approach, you will have to fetch all three names out of the database. - Although, you could probably combine the three queries into one, if you understand subqueries and/or joins.

If you use an index in your GET parameter, instead of (or with) the name, then you'd only need one query. Consider:
Expand|Select|Wrap|Line Numbers
  1. SELECT name FROM images
  2. LIMIT 1 OFFSET x
  3.  
Where [il]x[/il] represents the index of the image you want to fetch.

3 5868
Atli
5,058 Expert 4TB
Hey.

All you are doing there is creating Next and Prev links with the name of the image you are currently on. What you need to do is link to the next or previous images in the list.

Generally, you want to link to things like this using an ID or an index; a number that you can add or subtract from. That makes it far easier to create the links. All you'd have to do is add or subtract one from the current ID/index. - If you want to use a name, you will need to fetch the names of the next and previous images from the database and put those in the link. That would require at least one other query, to fetch those.

Consider that you can use queries like this one to find the name of the previous image, based on the name of the current image:
Expand|Select|Wrap|Line Numbers
  1. SELECT name FROM images
  2. WHERE id < (
  3.     SELECT id FROM images WHERE name = 'current name'
  4. )
  5. ORDER BY id DESC
  6. LIMIT 1;
  7.  
Then you can just flip the where condition and the order by orientation to get the next image.
Jan 25 '14 #2
slsv
14
So I need 3 query's?
1. To select all images from table
2. To select prev image on Prev button
3. To select next image on Next button

Or I didn't understand something?
Jan 25 '14 #3
Atli
5,058 Expert 4TB
Yes, if you want to go with the name approach, you will have to fetch all three names out of the database. - Although, you could probably combine the three queries into one, if you understand subqueries and/or joins.

If you use an index in your GET parameter, instead of (or with) the name, then you'd only need one query. Consider:
Expand|Select|Wrap|Line Numbers
  1. SELECT name FROM images
  2. LIMIT 1 OFFSET x
  3.  
Where [il]x[/il] represents the index of the image you want to fetch.
Jan 25 '14 #4

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

Similar topics

0
by: Ashok | last post by:
I have developed a custom IE application in C# using webbrowser control. But i am facing couple of issues when user clicks on an Exit link on a page the application is getting grayed out, but not...
2
by: RB | last post by:
Hi All, The ASP.NET Datagrid's pagination capability allows me to display either the Next/Prev buttons or the Page numbers to allow the user to navigate through the datagrid page by page as...
13
by: Joseph Garvin | last post by:
When I first came to Python I did a lot of C style loops like this: for i in range(len(myarray)): print myarray Obviously the more pythonic way is: for i in my array: print i
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
0
by: hime | last post by:
hi all; I have a web form to enter data in my table i am trying to add a Next & previous buttons but it's not working am using (.Net C# and MySql DB). and in the form I used textboxs to show the...
0
by: chixor1 | last post by:
Im hoping someone can help, I am working on a small program for class and have an array coming from a txt document. My application populates the array and data when I open it, however I am having...
1
by: shapper | last post by:
Hello, Is it possible to use images as Next / Previous buttons on an Asp.Net 2.0 GridView? Thanks, Miguel
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
1
by: mfaisalwarraich | last post by:
hi everybody, im trying to make next and previous buttons. im displaying record based on a search. when any image on the search results is clicked then dat image opened in a new page with details...
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: 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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.