SitePoint Sponsor

User Tag List

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

    Question mysql: retrival of info from databse count problem

    i have a database with mysql
    i can retrieve the data from the table and have it displayed

    what i have been trying to do is have it count each row and put the row number at the begining of each displayed row

    i dont want to have these numbers in the table, cause if i delete a row then the display of the table will have missing numbers

    is what i am trying to achieve possible
    have tried various count methods, none have been successful

    hope somebody can help me
    - the best things in life are for free -

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With some smaller changes, this should work for mysql too:

    http://www.sitepointforums.com/showt...threadid=67469

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    "smaller changes?"

    more like major surgery -- subselects don't work at all in mysql before release number whatever-it-is

    by the way, that code is pretty slick
    Code:
      select (select count(t1.id) 
                from table as t1 
               where t1.id <= t2.id)  as numrows
           , t2.id                    as id
           , t2.field1                as field1
        from table as t2
    order by t2.id
    without being able to use subselects, it's still possible, i think, with a join, although i haven't worked it out myself -- i mean, why bother? every "real" database can do subselects
    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
  •