By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,812 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,812 IT Pros & Developers. It's quick & easy.

go to previous,next records..

P: 16
in my project, a table called 'hardware' contains merely 5000 records..its a mysql database.. the user can add, modify or can view this hardware details one by one.. while clicking 'view' button, the user is redirected to 'hardware_view.php' page and can view the hardware..

my question is.. while the hardware_view.php is loaded, it has to retrieve the first record from the db and has to display the values.. this page contains previous, next buttons.. while clicking next button, it has to display the next record and for previous button also the same... how to do this?.(while the page is loading itself, the records has to be displayed.. and according the next,previous buttons it has to move to corresponding records...)
Jan 31 '09 #1
Share this Question
Share on Google+
13 Replies


pradeepjain
100+
P: 563
At the present when user clicks views button 'hardware_view.php' must have the current ID/particular ID regarding to the item from the Db to display its details .give the link to the previous button saying (current ID-1) and next button (current ID+1) .This must help u with ur query .
Jan 31 '09 #2

P: 16
i dont have any ID.. because, if i delete any record from table, for example say 500, tat ID wont exist in the table.... so in table records like, 1,2..,499 then 501...etc will be available.. so i cant just increment or decrement to view the record.. so i dint have tat field..
Jan 31 '09 #3

pradeepjain
100+
P: 563
@sweetline priya
oh ok!!! u can always say in your mysql query at the end that limit 3 order by ID i guess....so that u get 3 available ID's and update the previous and next button.Try this ..
Jan 31 '09 #4

P: 16
ok sure... thank u for ur immediate reply..
Jan 31 '09 #5

Atli
Expert 5K+
P: 5,058
For this particular purpose, you would want to use the LIMIT clause, pradeepjain is right.
You would simply pass the position of the item you want displayed as a GET or SESSION value, and them fetch it by adding "LIMIT #position, 1" to your SQL query.

But you should always try to include an ID clause in your tables, as a "row counter" of sorts. A field which uniquely identifies each row, even if there are gaps in the count.
If may be (and probably will be) useful later on.
Feb 1 '09 #6

P: 16
i ve used 'mysql_data_seek' function to retrieve the record from table... this is too functioning properly..

i ve another problem.. ie, i am dynamically creating a table and textboxes to display the values of each record..

during the page_load, first record should be displayed.. for that i ve written a code that should be executed only when the page is loaded for the first time(not executed during the button click)... during the page_load, i am checking if($n==0), if this condition is satisfied, this code is executed.. after displaying the values during the first page_load, i make the value $n=1, thus, the code within the condition($n==0) will not be executed again...

and i ve seperately written code(ie dynamic creation of tables) for 'next', 'prev' buttons.. this code within each post value of these buttons are executed accordingly.. my doubt is whether this is a proper way, is this a good coding... can anybody suggest and guide me???
Feb 1 '09 #7

TheServant
Expert 100+
P: 1,168
For your checking if code is executed you could look into the include_once() function ( http://au2.php.net/include_once ) or start storing $n as a session variable: $_SESSION['n'] so you can change it and it is available for that session.
For your next/prev buttons, you can either do something with the $_SESSION or use a $_GET variable. Usually for pagination you use GET variables.
Here is a good pagination link: http://www.tonymarston.net/php-mysql/pagination.html

I hope this helps.
Feb 1 '09 #8

P: 16
thank you for ur suggestions :)
Feb 2 '09 #9

TheServant
Expert 100+
P: 1,168
No problem. Let us know how you go.
Feb 2 '09 #10

P: 16
@TheServant..

u suggested to prefer 'pagination'.. but i want one record in a page.. so should i limit the num_of_records per page as 1 ???
Feb 2 '09 #11

pradeepjain
100+
P: 563
@sweetline priya
hey ur concept is similar to pagination as the page in which ur in will be static giving link to next and behind page.
Feb 2 '09 #12

P: 16
ok.. i ll try with pagination
Feb 2 '09 #13

TheServant
Expert 100+
P: 1,168
@sweetline priya
Give it a go, and post back with your code so that we can make sure it's the best way to do it. Also obviously let us know if you get stuck with the pagination code too ;)
Feb 3 '09 #14

Post your reply

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