Creating a table per user in PHP? [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'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.

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

Dynamic data matching between users based on user selection [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
I'm hoping one of you more experienced programmers might be able to shed some light on this situation:
My site allows users to create a profile and enter in their favorite musicians, all of which reside in a pre-existing database of musicians.
Based on the artists they select, I want to display to them other users who have selected the same artists.
Can anyone offer suggestions on how this could be effectively accomplished?
I'm using SQL and PHP for the back end.
You would need to create a cross-reference table between users and musicians that defines the 'likes' relationship. At a minimum it would just need to contain the user id and musician id.
CREATE TABLE user_likes_musician (
user_id INT NOT NULL,
musician_id INT NOT NULL,
PRIMARY KEY(user_id, musician_id)
);
To find users who liked a particular musician you can just join the likes table with the users table:
SELECT * FROM users
JOIN user_likes_musician
ON (users.ID = user_likes_musician.user_id
AND user_likes_musician.user_id <> [current user id]
AND user_likes_musician.musician_id = [musicians id]);

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