1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php And sql help.

Discussion in 'Programming' started by joesgraphics, Jan 13, 2007.

  1. #1
    HI i want to add an id to every member on my topsites list to use on a rating script iv made what is the sql so every time a member joins they will get a difrent id like so it counts the amount of ids and then +1 for the id if you no what i meen. :)

    Thanks in advanced.
     
    joesgraphics, Jan 13, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Set up the table so that the ID field is a primary key and is set to auto-increment.

    Then when you insert rows, it will automatically add the id as the next number. If you are using mysql, you can then find what the id is for the row you just inserted with mysql_insert_id().
     
    rodney88, Jan 13, 2007 IP
  3. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What is the sql for that im geting errors whe i try and do the sql query thanks for your help.
     
    joesgraphics, Jan 13, 2007 IP
  4. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    You got to show us the code or the sql query :rolleyes: :cool:
     
    [*-AnOnYmOuS-*], Jan 13, 2007 IP
  5. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ALTER TABLE `table name` ADD `id` VARCHAR( 11 ) NOT NULL AUTO_INCREMENT FIRST


    error = #1063 - Incorrect column specifier for column 'id'
     
    joesgraphics, Jan 13, 2007 IP
  6. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #6
    id has to be numeric.. use int, not varchar.
     
    rodney88, Jan 13, 2007 IP
  7. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    now i get this error: #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
     
    joesgraphics, Jan 13, 2007 IP
  8. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ALTER TABLE `table name` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY
    Code (markup):
     
    rodney88, Jan 13, 2007 IP
  9. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    still dont work. error = #1068 - Multiple primary key defined
     
    joesgraphics, Jan 13, 2007 IP
  10. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You need to drop the existing primary key.

    If you want someone to do it for you, hire a programmer. Otherwise use a little common sense and don't expect everything on a silver plate. Every error message so far has been in plain english which you could easily solve with a little research and trial and error. There's plenty of people happy to help but you need to help yourself as well.
     
    rodney88, Jan 13, 2007 IP
  11. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ok thanks now i look i can see what is wrong i dono why it did no pop in to my head when i looked int eh first place stupid me.
     
    joesgraphics, Jan 13, 2007 IP
  12. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    If i drop the existing primary key and that is username will the database still work the same as befor and what is the sql to drop the existing primary key thanks for all your help. :)
     
    joesgraphics, Jan 13, 2007 IP
  13. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #13
    No the database will not work the same.
    Everytime the script tries to use the "username", you will get error messages.
    You can use the username in your rating script, instead of creating a new field which I think will have the same value as the username has...
    Bye :)
     
    JEET, Jan 13, 2007 IP
  14. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    The voting script uses ids iv tryed includeing their username but it does not work i think it is because ids only acepts numbers if im right.

    Iv worked away round useing that table iv made a new post in databases with alot more info here is the url to it.
    http://forums.digitalpoint.com/showthread.php?t=218575

    Thanks for all your help every 1.
     
    joesgraphics, Jan 13, 2007 IP