SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    specific output from MYSQL

    hi, there are some record stored in a table and i want to retrieve some record , can i add serials numbers in front of every record?
    i.e there is a table
    index name designation
    ==============================
    1 tom clerk
    .
    .
    22 jeck clerk
    .
    .
    100 Harry clerk
    .
    .
    1001 Rohit clerk
    a table like this...
    ------------------------------------------------------------------


    i want out put like this

    1. tom clerk
    2. jeck clerk
    3. harry clerk
    4. rohit clerk


    means i want a serial no. with every record from database.....
    as 1,2,3,4 are the serial no. for every record , as its not stored in database... but i want to add it in out put...

    and iwant to use this serial no further in my programe...

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you ~have~ a program, i.e. application code written in some language like php, then the best place to append the row numbers is right there in your application language as you loop over the returned rows

    doing it with SQL is a ~lot~ more complicated and inefficient
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya its ok...


    but major prob is that, i want to show that records on a web pager, the records may exceed more than 1 page...

    so its hard to maintian a counter on diff pages...

    and i dont want to pas that counter argument in addressbar....

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    use LIMIT

    - on the 1st page, your query would have LIMIT 0,20 for the first 20 rows
    - on the 2nd page, your query would have LIMIT 20,20 for the second 20 rows
    - on the 3rd page, your query would have LIMIT 40,20 for the third 20 rows
    - and so on

    no row numbers required

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •