Create Hidden Association in PHP/MySQLi [closed] - php

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

Related

Need search a value from database from comma separated string [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 7 years ago.
Improve this question
I have a table in database that is TEXT field. In this table i have stored my product ids . Now when i go to cart and get all product id of cart i want to match from database field and get only those ids that there stored in product id.
Please see image first.
In this field you will see "check_values" field. here all product ids are stored in comma separated.
Let me take a example
Like i have purchase a product that product id is 161. So i want to match 161 id from "check_value" filed and get only those ids (from images) that having 161.(11,14,15).
Hope you understand my question.
You can use FIND_IN_SET e.g.
SELECT * FROM images WHERE FIND_IN_SET(161, check_values) > 0

How do i set up tables in an mysql database based on member positions? [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 7 years ago.
Improve this question
I am trying to set up tables in a mysql database so that a member can be assigned a position based on their section, group and role.
So if i had a form with three drop down boxes in html like so:
<form>
<select name="section"></select>
<select name="group"></select>
<select name="role"></select>
<button name="setPosition">Set Position</button>
</form>
How do I set up the sql tables so that each drop down can show whats available from there respective table based on the previous selection, and how would the member be assigned to that position in the database?
Thanks,
Edit: Sorry from not being clear, I know how to use ajax to get query's from a database and populate the selects with that data. What I need is the sql tables to be set up so that the selects can be context based, so for example, If I select a value from 'section' the 'group' shows all the groups in that section, which it gets from said table.
The standard way to set this up would be like this, with a members table that holds the id's for the other related tables, it's called "normalizing" the data.
table name columns
--------------------------------------------------
members section_id, group_id, role_id
sections id, section_name
groups id, group_name
roles id, role_name

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.

Many to many relationship with Mysql & PHP [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 9 years ago.
Improve this question
Let' say I Have 2 tables, webpage table, and a keywords table. It's a many to many relationshiop, right? One webpage can contain more than one keyword, and one keyword can be part of more than one webpage.
Webpage table contain id field as PK, and few other fields. Keywords table contain id as a PK, and also a few other fields. Third table, a child table, should contain id fields from both parent tables? Is it posible to track many to many relationship, with no foreign keys, just declaring this 2 id fields in child table as UNIQUE?
With or without FK's, when inserting new keywords for example through PHP, how should I refer, to which webpage this new keyword belongs, webpage id in a webpage table, or a id in a child table?
I would do something like this...
Table1
Table_WebPage
PageID, PageName, Url,...........
Table2
Table_KeyWords
WordID, Word, .........
Table3
Table_PageKeyWords
ID, PageID, WordID
Dont know why you want to do it without FK, Having FKs will enforce the data integrity and stop garbage data coming into your tables.

Creating a table per user in PHP? [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'm very new to all this...and for a project work in my college I have decided to make an online shopping website.
I am stuck at the sign up part.
I wanted the users to have a separated table for themselves that allow them to store the products that they have added in their cart so that they can keep adding more products later as well.
But as I read in other questions in all your links, creating a table per user seems to be a very bad idea.
but otherwise how can I do it? Please help.
Let me explain in detail.
I guess you have already created table for user and product. if not then you need to create table for user and product with unique value of user_id and product_id respectively.
Now create user_shopping cart table with following fields
user_id
product_id
product_qty
You can update user_shopping as per you need.
Make one table that contains the columns user_id and product_id.
That way you can associate products with users without needing a table for each user.

Categories