Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:44+00:00 2026-06-15T23:56:44+00:00

I’m trying to create a search function where a user can find a list

  • 0

I’m trying to create a search function where a user can find a list of events by selecting multiple music styles (via checkbox) that they’re interested in. Each event can have multiple music styles attached to it, and if one of the music styles searched for matches with an event – then it should show up.

This is where I’m stuck, because since each event has multiple music styles attached, they have to be stored in a different table.

One table events_music_styles contains the event_ID and music_style_ID
And the second, music_styles contains the names of those music styles in different languages.

This is how I joined them in MySql and it works nicely when I want to show all events and their corresponding music styles.

SELECT
    events.ID,
    events.EVENT_NAME,
    GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM events
INNER JOIN events_music_styles
    ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
    ON events_music_styles.music_style_id = music_styles.id
GROUP BY events.ID

However, when I submit a search query, the data variable looks like this: var MusicStyles = 1,2,3,5,20 …. Each of those numbers should be the ID of events_music_styles.

How would I split those numbers up and send them to my php file which looks like this?

var MusicStyles = $("#music").val();
$.ajax({
                type: "POST",
                url: "do_search.php",
                data: {
                    dataFromDate: FromDate,
                    dataToDate: ToDate,
                    dataMusicStyles: MusicStyles,
                    dataLocations: Locations,
                    dataFromPrice: FromPrice,
                    dataToPrice: ToPrice
                }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:56:45+00:00Added an answer on June 15, 2026 at 11:56 pm

    You can leave the javascript part as it is. On the PHP side you can use the comma separated list in an SQL IN() statement.

    <?php
    
    // JQuery as used in the question will send the 'MusicStyles' post var in 
    // array form. This means that the raw post contains multiple occurences 
    // of 'MusicStyles[]'. Note the [] at the end.
    // PHP will convert such post vars automatically to an array.  
    // In this case we'll have to flatten the array to a comma separated list first
    if(is_array($_POST['MusicStyles'])) {
        $musicStyles = implode(',', $_POST['MusicStyles']);
    } else {
        $musicStyles = $_POST['MusicStyles'];
    }
    
    $query = 
    "SELECT
        events.ID,
        events.EVENT_NAME,
        GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
    FROM events
    INNER JOIN events_music_styles
        ON events.ID = events_music_styles.event_id
    INNER JOIN music_styles
        ON events_music_styles.music_style_id = music_styles.id";
    
    if(!empty($musicStyles)) {
        // you can use the comma separated list as param for the IN statement
        $query .= " WHERE music_styles.id IN($musicStyles)";
    }
    
    $query .= " GROUP BY events.ID";
    
    // ...
    

    Note: This is just an example. Of course you should validate the incoming $_POST values before using them in a MySQL statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.