go to previous,next records..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetline priya
    New Member
    • Jan 2009
    • 16

    #1

    go to previous,next records..

    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.p hp 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...)
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    #2
    ways

    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 .

    Comment

    • sweetline priya
      New Member
      • Jan 2009
      • 16

      #3
      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..

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        Originally posted by sweetline priya
        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..
        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 ..

        Comment

        • sweetline priya
          New Member
          • Jan 2009
          • 16

          #5
          ok sure... thank u for ur immediate reply..

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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.

            Comment

            • sweetline priya
              New Member
              • Jan 2009
              • 16

              #7
              i ve used 'mysql_data_see k' 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???

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                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.

                Comment

                • sweetline priya
                  New Member
                  • Jan 2009
                  • 16

                  #9
                  thank you for ur suggestions :)

                  Comment

                  • TheServant
                    Recognized Expert Top Contributor
                    • Feb 2008
                    • 1168

                    #10
                    No problem. Let us know how you go.

                    Comment

                    • sweetline priya
                      New Member
                      • Jan 2009
                      • 16

                      #11
                      @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 ???

                      Comment

                      • pradeepjain
                        Contributor
                        • Jul 2007
                        • 563

                        #12
                        Originally posted by sweetline priya
                        @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 ???
                        hey ur concept is similar to pagination as the page in which ur in will be static giving link to next and behind page.

                        Comment

                        • sweetline priya
                          New Member
                          • Jan 2009
                          • 16

                          #13
                          ok.. i ll try with pagination

                          Comment

                          • TheServant
                            Recognized Expert Top Contributor
                            • Feb 2008
                            • 1168

                            #14
                            Originally posted by sweetline priya
                            ok.. i ll try with pagination
                            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 ;)

                            Comment

                            Working...