SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb problem in table field and Duplicate entry '0' for key 1 .... Help !

    hello ,

    please i have small problem

    i have two tables in database ,,

    table1 contain this columns :
    -id
    -name

    in table 2 i added 1 column which is share with table one
    so table2 contain this columns:

    -name
    -st
    -table1id


    now i want add more than one id to the shared table1id in table2 . how ?

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

    could you please be a bit more specific?

    maybe show actual values for what you're doing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello Mr.r937

    i will explain more .. no i have two tables , the first table is to available file extensions to upload , which contain this columns :
    id
    extname


    the second table is to members groups premissions , it's contain each members group and it's availble file extensions to upload , i added in it shared column between members groups table and extensions table , so memgroup table contain :
    -id
    -grname
    -extid

    which extid column i shared between memgroup table and id column in ext table .
    i want now assign in extid column in memgroup table more than ext id (because to available more than file extension to upload by this group)

    so help me or advise me another method to do what i mean

    Thanks,

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    sorry, i do not understand what you're doing

    please show sample rows, and please do a SHOW CREATE TABLE for each table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    ok i waill write by sql :

    i have two tables in a database :

    first tabe is extensions which contain files extensions which added by user
    PHP Code:
    CREATE TABLE extensions(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,name VARCHAR(10NOT NULL); 
    second table is members_group which contain groups permissions to site members ,
    PHP Code:
    CREATE TABLE groups(id INT NOT NULL PRIMARY KEY AUTO_INCREMENt,name VARCHAR(255NOT NULL,extensionsid INT); 
    The extensionsid field associates each row in groups with
    a row in extension.(simple relationship) and which mean it contain id's to extensions that user which belong to this group can use it .

    now let's say we have this extensions with ids in extensions table
    |id| |name|
    1 mp3
    2 avi

    and groups table contain :
    |id| |name| |extensionsid|
    1 members 1

    when i insert into groups table and extensionsid field , it assign only one value so in extensionsid in groups table i want add more than id in it to be like this :
    |id| |name| |extensionsid|
    1 members 1,2,3,4

    is it possible , if yes . How ?

    i hope that you are understand what i want to do

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    ah, you want to add more than one id in a single value

    my advice: don't

    (re)design your table so that each group can have more than one row -- one for each extension
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tahnks Alot r937
    i have another question plz , i want know what's the meaning of this error message :
    Duplicate entry '0' for key 1
    and what are causes of it to occure ?

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    it means you are trying to insert the value '0' more than once (i.e. a duplicate) into a column which has a unique key

    what causes the error message? you
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what causes the error message? you
    thanks r937 .. i'm very proud of your frank


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
  •