SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    PHP Programmer QReyes's Avatar
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    698
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Increment value for each row

    I've been trying to find a solution for this dilemma for the past 4 HOURS already! I would be grateful if someone could help.

    What I would like to do is insert an incrementing value for ordering (see code below) so that each row, ordering will have +1 value from the previous value. I've tried it with the code below but this doesn't seem to work:

    PHP Code:
    UPDATE `my_tableSET `ordering` = LAST_INSERT_ID(`ordering` + 1ORDER BY created_date ASC
    I'm only using MySQL v4.0.20a, so looping suggestions (as part of MySQL v5) wouldn't help.
    The Star Circle Quest Community - Community website for SCQ fans.
    Telebisyon.net - Reference guide to TV series shown in the Philippines.
    Lyrics Server Online! - All the lyrics you can get on one website.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    have you tried an auto_increment column?

    and, if i might ask, why do you need them to be consecutive? what's this for? perhaps you don't need to do it at all...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    PHP Programmer QReyes's Avatar
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    698
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't work.
    The Star Circle Quest Community - Community website for SCQ fans.
    Telebisyon.net - Reference guide to TV series shown in the Philippines.
    Lyrics Server Online! - All the lyrics you can get on one website.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what didn't work?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    PHP Programmer QReyes's Avatar
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    698
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turning the column into auto_increment.
    The Star Circle Quest Community - Community website for SCQ fans.
    Telebisyon.net - Reference guide to TV series shown in the Philippines.
    Lyrics Server Online! - All the lyrics you can get on one website.


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
  •