Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old May 1st, 2003, 01:35 PM
Aaron Aaron is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Aaron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
Original - php Code
  1. $sql = "UPDATE port_images SET
  2. full='$full',large='$large',medium='$medium',small 
  3. ='$small',invID='$invID'
  4. WHERE imgID=$id";

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:
Original - php Code
  1. CREATE TABLE port_images (
  2.  
  3.   invID int(10) NOT NULL default '0',
  4.  
  5.   imgID int(10) NOT NULL default '0',
  6.  
  7.   full varchar(255) default NULL,
  8.  
  9.   large varchar(255) default NULL,
  10.  
  11.   medium varchar(255) default NULL,
  12.  
  13.   small varchar(255) default NULL,
  14.  
  15.   PRIMARY KEY  (invID,imgID)
  16.  
  17.  
  18.  
  19. CREATE TABLE port_inventory (
  20.  
  21.   authID int(10) NOT NULL default '0',
  22.  
  23.   invID int(10) NOT NULL auto_increment,
  24.  
  25.   artist varchar(100) default NULL,
  26.  
  27.   title varchar(255) default NULL,
  28.  
  29.   medium varchar(255) default NULL,
  30.  
  31.   year year(4) default NULL,
  32.  
  33.   date date NOT NULL default '0000-00-00',
  34.  
  35.   sizeH char(3) default NULL,
  36.  
  37.   sizeW char(3) default NULL,
  38.  
  39.   PRIMARY KEY  (invID)
  40.  
  41.  
  42.  
  43.  
  44.  
  45. CREATE TABLE port_text (
  46.  
  47.   invID int(10) NOT NULL default '0',
  48.  
  49.   txtID int(10) NOT NULL default '0',
  50.  
  51.   text text,
  52.  
  53.   who varchar(255) default NULL,
  54.  
  55.   what varchar(255) default NULL,
  56.  
  57.   where varchar(255) default NULL,
  58.  
  59.   when varchar(255) default NULL,
  60.  
  61.   PRIMARY KEY  (invID,txtID)

I am sure there are many obvious errors, but I am dense.
Many thanks.

Reply With Quote
  #2  
Old May 1st, 2003, 01:54 PM
mugane mugane is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Charlottesville, VA USA
Posts: 425 mugane User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to mugane Send a message via Yahoo to mugane
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?

Reply With Quote
  #3  
Old May 1st, 2003, 04:09 PM
Aaron Aaron is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Aaron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > multiple feild primary key


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway