1,105,254 Community Members

Mutiple Value Column

Member Avatar
whit89
Light Poster
48 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

Say i have a series of items , so items have multiple people associated with them

Item_id type_id person_id
1 1 1,2
2 1 3,4
3 2 1,3


Will this work when i search for them in php
say display
people with item one
person 1 and person 2

Member Avatar
smantscheff
Nearly a Posting Virtuoso
1,289 posts since Oct 2010
Reputation Points: 265 [?]
Q&As Helped to Solve: 271 [?]
Skill Endorsements: 8 [?]
 
0
 

It is not a question of PHP. PHP can display anything which the database delivers.
Your database query is a very basic one. I suggest you take a mysql primer course before you ask more questions which you will know how to answer after the first lesson.

Member Avatar
whit89
Light Poster
48 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I may have explained this badly
Say a restaurant has courses and meals but some courses contain the same meal

meal_id , meal_desc , course_id

course_id , course_desc

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
0
 

Your second example is much better. You were trying to fit too much data into inappropriate columns in your first post.
Now if you wanted to find all courses that were part of a particular meal you can use SQL to extract the data form the database by joining the tables.
Do you have a real example of what you are trying to do and so code to show how far you've got so far?

Member Avatar
whit89
Light Poster
48 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Im trying to create an adobe filter system where people can find what software is right for them.

Say Dreamweaver

Software_id Software_name software_type
1 dreamweaver design,web
2 photoshop design
3 flash design,web

would i be able to search this table with php? so say find all software that is design or web or design and web.

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
1
 

No, you shouldn't hold two pieces of data in the same column. Having design and web in the same column matched against dreamweaver (for example) is incorrect.If you wanted to do this you would need at least 2 tables.

table 1: software
software_id
software_product
software_desc

table 2: software_uses
software_id
usage

So, in table 2 for dreamweaver you would have two rows (based on your example above and giving dreamweaver an id of 101).
software_uses
101 web
101 design

Now you can search for any software that matches a particular need and retrieve the name and description from table 1 using an SQL join.
Does that help?

Member Avatar
whit89
Light Poster
48 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

ah so two thing can have the same id?

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
0
 

Yes, as long as the column for the ID isn't defined as the sole primary key for the table. Tables like table 2 above are sometimes called linking tables as they form the relationship between two other tables. For example, you could have another table called uses and in that table name and describe the various things software could be used for (design, web, video editing, etc) and then table 2 forms the link between uses and software and would simply hold 2 columns - software_id and uses_id. Table 2 then allows all of the information in the tables to be joined in searches.

Member Avatar
rajeevphp2011
Light Poster
26 posts since Nov 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 1 [?]
 
0
 

select person_id from table where item_id = '1' ;

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article