#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    17
    Rep Power
    0
    I have this table with 2 columns, id and content. Id is an auto-incrementing column. My php script produces a random number from 1 to number of rows in the table, and then displays the content for that row matching the random number to id. The problem is that if i delete a row, and the random number matches the id of the row deleted, that id will no longer exist. I could write some code to check for the id's existance, but is there another way to reset all of the id's in the id column?

    Thanks in advance for any help!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    There is another way and you could even do it from an sql batch file, but would you want to?

    The 5 easy pieces...

    > alter table table_name modify id int not null;

    > alter table table_name drop primary key;

    > alter table table_name modify id int;

    > update table_name set id=NULL;

    > alter table table_name modify id int not null auto_increment primary key;

    I believe that should do it, but my suggestion would be to read all the ids from the table into an array and then randomly choose one from that array, so you know it exists.

    Better yet, try

    > select id, content, content*0+RAND() as rand_col from table_name order by rand_col limit 1;

    Kyuzo

    [This message has been edited by Kyuzo (edited July 12, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    17
    Rep Power
    0
    Thanks Kyuzo, that worked fine.

Similar Threads

  1. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  2. how do I create a dynamic table row ??
    By rshinwell in forum PHP Development
    Replies: 0
    Last Post: August 28th, 2002, 09:40 AM
  3. Replies: 4
    Last Post: August 27th, 2002, 03:23 AM
  4. Replies: 3
    Last Post: August 27th, 2002, 01:34 AM
  5. Updating table row with innerHTML
    By christo in forum HTML Programming
    Replies: 2
    Last Post: February 18th, 2002, 01:54 AM

IMN logo majestic logo threadwatch logo seochat tools logo