Take the 2-minute tour ×

I'm working on an CMS which is based on an database of course. The structure of the database is as follow (the language of this is Dutch):

id, artikelnummer_fabrikant, breedte, diepte, hoogte, extrainfo, afmeting, kleur, merk, serie, producttype, omschrijving, prijsfinal, levertijd

With the next piece of code I get all the information out of the database and place it in a table:

(Sorry that I dont use < and > to create the tags, this text editor sees it as tag and not as text and I have no idea how to make this work correct, anny tips on this will be welcome!)

function get_content() {

echo "<p>";
echo "<table>";
echo "<tr>";
echo "<td> id </td>";
echo "<td> artikelnummer frabrikant </td>"
and so on
echo "</tr>";

$sql = "SELECT * FROM products";

if (mysql_num_rows($res) != 0) :
while ($row = mysql_fetch_assoc($res)) :
echo "<tr>";
echo "<td> . $row['id'] . </td>";
echo "<td> . $row['artikelnummer_fabrikant'] . </td>";
and so on
echo "</tr>";

echo "</table>";
echo "</p>";


Now I would like to build a filter on this with the tags select and option so that when I select the option brand(merk) 'windsor' it will show all products with the brand 'windsor' with all there information such as breedte, hoogte, diepte (width, heigt, depth).

I got a piece of code which gives me all the brands(merk) in an option menu:

function category_filter() {

echo "Merk: ";
echo "<select onchange=window.location = this.value>;";
$sql = "SELECT merk FROM products";

if (mysql_num_rows($res) !=0 ) :
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) :
echo "<option> . $row['merk'] . </option>";
echo "</select>";

And of cource I have 1 for each item in the database.

What I want to do next is combine these 2 codes in some kind of way that when i select the brand(merk) 'Windsor' in the option menu brand(merk) it will show all products with the brand 'Windsor' + all the other information of that product.

I'm struggeling for a week trying to make this happend and I can't get it going like the way i want it to go :(.

How can i make this work?

share|improve this question
Please use the format code button... I would do it, but you added so many html tags... –  Neal Mar 18 '13 at 15:38
why are you writing all the HTML-tags without <> ? –  michi Mar 18 '13 at 16:09
Hello @AarolamaBluenk i heard about this indeed, stupid of me to still use mysql. I'm gonna use mysqli instead. michi I did not know how to use them in the editor, when i used them they were actually used as code instead of text. neal how would you build the code using mysqli? –  Ger989 Mar 19 '13 at 9:28
@michi Edited th tags –  Ger989 Mar 19 '13 at 13:09
show 5 more comments

1 Answer

Ok so i found out how to do this by writing the following code:

    echo    "<form class='merk' action='index.php'>";
        echo        "<select name=merk>";
        echo            "<option value=''>Kies een merk</option>";

        while ($row_merk    =   mysqli_fetch_array($merk_query_selected)) :

        $filter =   $row_merk['merk'];

            if($filter == $merk) :
                echo    "<option value=" . urlencode($filter) . " selected='selected'>" . $filter . "</option>";
            else :
                echo    "<option value=" . urlencode($filter) . ">" . $filter . "</option>";


        echo        "</select>";        
        echo        "<input class='input-merk' type='submit' value='Filter op merk'>";
        echo    "</form><br />";

        var that = $(this);
        $.post(that.attr('action'), that.serialize());

Have it decoded:

$merk                                       =   urldecode($_GET["merk"]);

And then get the contents by running this while loop:

while ($row_merk    =   mysqli_fetch_array($merk_query_all)) :
            echo    $table_row;
            echo        $table_cell, $row_merk['id'] . $table_div_end;
            echo        $table_cell, $row_merk['artikelnummer_fabrikant'] . $table_div_end;
            echo        $table_cell, $row_merk['breedte'] . $table_div_end;
            echo        $table_cell, $row_merk['diepte'] . $table_div_end;
            echo        $table_cell, $row_merk['hoogte'] . $table_div_end;
            echo        $table_cell, $row_merk['extrainfo'] . $table_div_end;
            echo        $table_cell, $row_merk['afmeting'] . $table_div_end;
            echo        $table_cell, $row_merk['kleur'] . $table_div_end;
            echo        $table_cell, $row_merk['merk'] . $table_div_end;
            echo        $table_cell, $row_merk['serie'] . $table_div_end;
            echo        $table_cell, $row_merk['producttype'] . $table_div_end;
            echo        $table_cell, $row_merk['omschrijving'] . $table_div_end;
            echo        $table_cell, $row_merk['prijsfinal'] . $table_div_end;
            echo        $table_cellEnd, $row_merk['levertijd'] . $table_div_end;
            echo    $table_row_end;

Now what i wanna do is make it dynamic so that it can filter on multiple selections at the same time.

Doing my best, anny help would be welcome!

[EDIT] Found out how this works, but its still not dynamic. But this question has been awnsered, I will go and look on the web how to make this dynamic.

share|improve this answer
add comment

Your Answer


