Jump to content

Php multiselect process from different tables


asanti
Go to solution Solved by Barand,

Recommended Posts

I have this 3 tables


  • users (id_user)
  • music_styles (id_style, style) ex. (1) - (Blues)
  • user_styles (id_user, id_style)

I'm trying to create a form in which the user ($user = $_SESSION['id_user']) chooses through a multiple select the styles of preference to store them in the database using mysqli statements.


If the styles prefered are selected they should be displayed in the select input later, how can i accomplish this?


Thanks.


Link to comment
Share on other sites

  • Solution

When you create the selection dropdown for music styles, use

SELECT ms.idstyle
    , style
    , id_user
FROM music_styles ms
    LEFT JOIN user_styles us
    ON ms.id_style = us.id_style AND us.id_user = $user

Those styles with a user id should be marked as "selected"

Link to comment
Share on other sites

When you create the selection dropdown for music styles, use

SELECT ms.idstyle
    , style
    , id_user
FROM music_styles ms
    LEFT JOIN user_styles us
    ON ms.id_style = us.id_style AND us.id_user = $user

Those styles with a user id should be marked as "selected"

 

Thanks Barand, what about the db process? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.