Mysql table design and implementation [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have this table that i want to create in my database:
ID--Name--Major1--Univ1--Major2--Univ2--Major3-Univ3
The problem is, maybe the user did 9 majors. What i'm going to do create a table of 18 columns of major and univ... So is there a dynamic technique followed for this type of situations?

Make 3 tables
Primary tables
Universities
id | name
Majors
id | name
students
id | name
bridge_table
student_major
students_id|university_id|major_id

You use two tables. :)
One table is the student table.
One table is the university / major table with a link to the student_id from the other table. Then a student can get unlimited majors. ;)

Related

What SQL query should I use to output the value of my 2 tables? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am a student and is new to MySQL
I have 2 tables, ors_uniform contains 7 products that has 9 sizes (XS-5XL).
ors_prices contains the fk of table1 and the prices per size (9 sizes)
I wanted it so that when I output the inventory of the products, the price will be shown next to it. I know how to do that using php already but I don't know what MySQL query to use.
I currently just use SELECT * FROM ors_uniform
2 tables
let's assume the fk is a foreign key and it is available in both tables.
select * from ors_uniform join ors_prices on ors_uniform.fk = ors_prices.fk;

Create several group based on their Interest-based [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Create several group based on their Interest-based. I am using php and mysql.
my user table
name_one
name_two
name_three
name_four
etc..
6.
7.
8.
I would to select some names and create a group
Ex:
256 users interest in football = Foot Ball group
549 users interest in cricket = Cricket Group
Note: Football users can be in cricket as well.
My question is how can I create many users group from user table rows. Should it create extra table? Please help me.
I suggest you to create a table interest(id_interest, name), then a 3rd table interest_user(id_user, id_interest)
I suggest using interest as table name instead of group because it has a special meaning in mysql.

How to make for each user, documents start by id 1? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to make database for users and every user have documents which will line up in this order for
user1(document1 have id 1, documnet2 have id 2, documnet3 have id 3, etc...)
user2(document1 have id 1, documnet2 have id 2, documnet3 have id 3, etc...)
?
Create two tables to accomplish this.
The first table should contain your users. Example:
|id|username|password|
|1|user1|1234|
|2|user2|1234|
Then create a second table containing your documents
|id|document|owner_id|document_id|
|1|adocument.doc|1|1|
|2|anotherdoc.doc|1|2|
|3|adocument.doc|2|1|
|4|anotherdoc.dco|2|2|
In this example you see that the documents in the document-table point to a owner_id. This should be the id of the user in the users table.
This is just to head you in a direction for a solution to your question. We cant write the entire code for you, so start googling a bit on mysql.

Should I have a foreign key of product in a table of items of a buy? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Let me explain; I've got two tables:
# tb_buy
buy_id
address_id
buy_value
# tb_buy_items
product_id - foreign key of a product table
buy_id
It's only an example, but is it recommended to use a structure like this?
Or should I put info about the product in tb_buy_items? Like name, cod, value, because if someone deletes this product, the line will be removed or it will set the foreign key to NULL and no-one will know that product was purchased...?
I would like some hints about this, thanks.
if ¨buy¨ table is for historical purpose (to hold the order history) I would just make a copy of all information that I would like to keep (code, name, price at that the purchased moment etc). just as you said, a change of product will affect all. but if it´s for ¨cart¨ table that should have most updated information, I will have the foreign key

Create Hidden Association in PHP/MySQLi [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a MYSQL Db that has a PROFILE-TABLE as well as a KEYWORD-TABLE which holds profiles and the other holds keywords associated with those categories.
Profile-Table
UserID
UserName
UserDept
UserPhoto
UserKeyword > indexes KeywordName (from Keyword-Table)
UserAssociations
Keyword-Table
KeyID
KeywordName
I need to make an association with the categories/keywords.
I want to add a hidden field (UserAssociations) onto my profile form which will display a hidden association where as when you click on a category via a link on the page, it will index first those that are associated. I have written this in PHP and use MYSQLI database.
I have never created associations before needing this. What would be the easiest way to achieve this functionality?
From what I gather, you wish to associate a user profile with keyword. What you need is another table to represent the relationship, something like this:
profile_keywords ( <UserID>, <KeyID> )
Hence, if UserID 4 has associated himself with keyword ID 3, you would have an entry in profile_keywords like this:
UserID, KeyID
---------------
3 4

Categories