Dynamic data matching between users based on user selection [closed] - php

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]);

Related

Vote any one team through application and one user can vote only single time in a day [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 6 years ago.
Improve this question
There is an application regarding Cricket Tournament there are few teams in that tournament . we can vote any one team through application and one user can vote only single time in a day How can be possible ,just share logic and thoughts.
U can do it with db.
In the DB u should create a table with columns like-
votes(
user_id,
team_id,
date,
......,
unique (user_id, team_id, date)
)
Then if a user gives vote, u should store votes here.
Look carefully there is a unique field in the database on user_id, team_id and date.
SO only one vote for one team by a user in a day can be possible.
Before storing a vote, u should check if there is a vote for the team by he user in that day already.
If yes, then u should not store the vote.
If no, then u should store the vote.
It will work for u.

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.

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

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.

Search in MySQL with Spaces [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 creating an app similar to Instagram. I have a photos table with a likers columns, showing which user_ids have liked a photo. For example, if user_id 1 and 5 like photo_id 51, then photo_id 51's likers column will show 1 5. As seen, the user_ids are separated by spaces. Now, like Instagram, I want to be able to show which username's are liking a specific photo. For this, I need to be able to get all the user_ids from the likers column separately. Can anyone help me with how to do this, or suggest an alternative way?
You're approaching this the wrong way. You almost certainly don't want to store multiple pieces of data in one field. You want to have something like this:
Table: User
- id
- blah blah
Table: Photo
- id
- blah blah
Table: Like
- user_id
- photo_id
This will allow you write very flexible queries, including what you described:
SELECT u.id
FROM User AS u
JOIN Like AS li ON li.user_id = u.id
WHERE li.photo_id = $current_photo_id
This is a topic known as database normalization. Please read more about it if you want your application to succeed.

Categories