|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
multiple feild primary key
Hi
As most here I am working on stuff. This is my first app and database from the ground up. Now to the point I have created the following tables to manage an art portfolio. For each piece there will be one "port_inventory" entry, there can be multiple "port_images" and "port_text" entries that relate to "port_inventory" (tables at end of post). When creating the tables I set invID in "port_inventory" as primary, in the other two tables I used invID and txtID or imgID as the primary key. In the tables images and text I did not set the primary key's to auto_increment, invID if it autos it will be different the the inv it is supposed to reference, the other two I did not so I could now how many instances were for each invID ( I was hoping for a primary key result like invID 1 txtID 1, invID 1 txtId 2 and so on) I one problem and another question. Question, is the way I have this a good idea? Or is there a better option for what I have done. The problem, I can add data to any of the tables, I am having problems when it comes to UPDATE of the fields here is the code I am using php Code:
I dont know how to choose multipe $id's, when I run this as I have it, it returns the form but with empty fields, and if I change the data, nothing is updated. php Code:
I am sure there are many obvious errors, but I am dense. Many thanks. |
|
#2
|
|||
|
|||
|
RE: multiple feild primary key
Try:
$sql = "UPDATE port_images SET full='$full',large='$large',medium='$medium', small='$small',invID='$invID' WHERE imgID='$id'"; // added ' to imgID=$id Use $result = mysql_query($query) or die(mysql_error()); to execute. As for your other concerns, I really have no idea what you are talking about. If you have a concern about your design stragtegy there is really no need to list a fleet of strangely-named variables, neglect to describe their relevance, and moreover use just a single paragraph for that enhanced readability everyone loves. Just outline the idea and specify what you think could be improved. Do you have any design diagrams? |
|
#3
|
|||
|
|||
|
RE: multiple feild primary key
Sorry for the confusing post.
Here is a better table diagram. port_inventory is the main table, the field invID is auto_increment, then used for the following table. The primary keys for the text and image tables is a combination of the id from that table and the invID. I did not set the id fields for text an image tables to autoincrement. Is this a sound design strategy, or should I have a field that is auto_increment? Or are there other problems that I should address at this stage. table port_inventory PRIMARY KEY (invID) -------------------------------------------------------------------------- | authID | invID | artist | title | medium | year | date | sizeH | sizeW | |------------------------------------------------------------------------ | 1 | 1 | artist name | title a | oil on canvas | 2001 | 01-01-2003 | 18 | 24 | | 1 | 2 | artist name | title b | oil on canvas | 1998 | 01-01-2003 | 24 | 24 | | 1 | 3 | artist name | title c | water color on paper | 2002 | 01-01-2003 | 24 | 36 | |------------------------------------------------------------------------ table port_images PRIMARY KEY (invID)(imgID) ------------------------------------------------- | invID | imgID | full | large | medium | small | |------------------------------------------------------------------------ | 1 | 1 | path/to/img a | path/to/img a | path/to/img a | path/to/img a | | 2 | 1 | path/to/img b | path/to/img b | path/to/img b | path/to/img b | | 3 | 1 | path/to/img c | path/to/img c | path/to/img c | path/to/img c | | 2 | 2 | path/to/img c | path/to/img c | path/to/img c | path/to/img c | |------------------------------------------------------------------------ table port_text PRIMARY KEY (invID)(txtID) ---------------------------------------------------- | invID | txtID | text | who | what | where | when | |--------------------------------------------------- | 1 | 1 | text about work... | kw who | kw what | kw where | kw when | | 2 | 1 | text about work... | kw who | kw what | kw where | kw when | | 3 | 1 | text about work... | kw who | kw what | kw where | kw when | | 1 | 2 | text about work... | kw who | kw what | kw where | kw when | |--------------------------------------------------- Thanks |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > multiple feild primary key |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|