I need help on building a mysql query.

I have 2 tables : list and type.
List : id_list, name
Type : id_type, id_list, name

The id_list column in table Type is a reference for id_list in the table List.

My HTML [main.php] :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript">
                function passList() {
                        var p=[];
                        $('input.first').each( function() {
                                if($(this).prop('checked')) {                                      
                        } );
                        var q=[];
                        $('input.second').each( function() {
                                if($(this).prop('checked')) {
                        } );
                        $.ajax( {
                                data: {list:p,type:q},
                                success: function(res) {

        <input type="checkbox" class="first" rel="list1" onclick="passList()">list1<br />
        <input type="checkbox" class="first" rel="list2" onclick="passList()">list2<br />
        <input type="checkbox" class="first" rel="list3" onclick="passList()">list3<br />
        <input type="checkbox" class="first" rel="list4" onclick="passList()">list4<br />
        <input type="checkbox" class="second" rel="type1" onclick="passList()">type1<br />
        <input type="checkbox" class="second" rel="type2" onclick="passList()">type2<br />
        <input type="checkbox" class="second" rel="type3" onclick="passList()">type3<br />
        <div id="result"> </div>        

I am passing the variables p and q as arrays p[] and q[] to process.php

process.php :

    if(isset($_POST['list'])&&!isset($_POST['type'])) {
      foreach ($_POST['list'] as $list) {
        echo "You selected $list<br />";

    if(isset($_POST['list'])&&isset($_POST['type'])) {
      foreach ($_POST['list'] as $list) {
        echo "You selected $list<br />";
      foreach ($_POST['type'] as $type) {
        echo "The type is $type<br />";    //   SELECT * from list inner join type on list.id_list = type.id_type WHERE id_type = [array]

Please help me understand how to create the MySQL query to include the array in WHERE clause.

Thank you

Member Avatar for LastMitch

Please help me understand how to create the MySQL query to include the array in WHERE clause.

I am a bit confused what you are trying to do?

You are using AJAX with PHP. It's always good to stick with one method.

What is your table structure? You didn't really provide one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.