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

  • SEARCH
  • Home
  • 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 9111543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:31:53+00:00 2026-06-17T03:31:53+00:00

I have a multiple select form that I am now trying to use with

  • 0

I have a multiple select form that I am now trying to use with AJAX. The drop down is supposed to act as a filter for images.

Index.php

<script>
function filterResults(str)
{
if (str=="")
  {
  document.getElementById("divResults").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("divResults").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","filter_ajax.php?filter="+str,true);
xmlhttp.send();
}
</script>

<form action="" class="css_form" id="picture_filter" name="picture_filter">
    <select onchange="filterResults(this.value)" multiple="multiple" name="filter[]" id="filter">
     <option value="filter_name_1">Filter name 1</option>
     <option value="filter_name_2">Filter name 2</option>
     <option value="filter_name_3">Filter name 3</option>
     <option value="filter_name_4">Filter name 4</option>
</select>
<div id="divResults"></div>

and filter_ajax.php

<?php

include ("connect.php");

    $filter = $_GET["filter"];
    $filterIn = implode("','",$filter);

        $result = mysql_query("SELECT * FROM edt_images
                                WHERE category1 IN ('$filterIn')
                                OR category2 IN ('$filterIn')
                                OR category3 IN ('$filterIn')
                                OR category4 IN ('$filterIn')
                                OR category5 IN ('$filterIn')
                                OR category6 IN ('$filterIn')")
            or die(mysql_error());
        while ($row = mysql_fetch_array($result)) {
            echo "<img src='files/small/thumb0_".$row['item_name'].".".$row['file_extension']."' border='0'/>"; 
        }

?>

In my database each image has six entries which correspond to the categories, and are filled with subcategories. Thus whats supposed to happen is that when an item is selected from the “filter drop-down” it should query each six columns for that information. However I am receiving the following error and output:

implode(): Invalid arguments passed in … Line 6.

For testing I have five entries. 3 which have all information filled in for the six categories entries, and two which were left blank.

The two that are left blank are always returned with the error above.

Anyone have any ideas as to why this is happening?

Thanks in advance

  • 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-17T03:31:54+00:00Added an answer on June 17, 2026 at 3:31 am

    Modify <select>:

    <select onchange="filterResults(this)" multiple="multiple" name="filter[]" id="filter">
    

    and try this (note: you don’t need to implode array with “,” on server-side – that is already done with JS in the example):

    function filterResults(sel)
    {
        var selectedOptions = [];
        for (var i = 0; i < sel.options.length; i++) {
            if (sel.options[i].selected) {
                selectedOptions.push("'" + sel.options[i].value + "'");
            }
        }
        if (selectedOptions.length == 0) {
            document.getElementById("divResults").innerHTML="";
            return;
        }
        str = selectedOptions.join(",");
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        } else  {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("divResults").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","test.php?filter="+str,true);
        xmlhttp.send();
    }
    

    UPD:
    Modify your SQL also:

    $result = mysql_query("SELECT * FROM edt_images
                                    WHERE category1 IN ($filterIn)
                                    OR category2 IN ($filterIn)
                                    OR category3 IN ($filterIn)
                                    OR category4 IN ($filterIn)
                                    OR category5 IN ($filterIn)
                                    OR category6 IN ($filterIn)");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form that has a multiple select drop down. a user can
In my form I have multiple select fields. See here http://jsfiddle.net/ZNShh/ Now I want
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I have a form that I used to filter search results that consist of
I have a form that contains multiple partners that share a pool. The partners
I have a form that allows for multiple file uploads. <input name=uploadedfile[] type=file multiple=true/>
I have a <select> form element where I create multiple <option> children based on
I have multiple multi-select boxes with the same class and i want to unselect
So I have two multiple select boxes like this <select id=foo multiple=multiple> <option value=1>Option
I have a stored procedure with multiple insert/select statements. Let's say I'm using the

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.