I have created an ecommerce website can anyone help me out and let me know that how do i ake a product flter or refine search what ever we say using checkboxees or anyone could sugest any tutorial please.

Thank You in advance

Recommended Answers

All 5 Replies

Your question is not all that understandable but the little knowledge I have is that you are trying to filter the results returned from a search field.

My suggestion is that you can make this asynchronously with AJAX. But if you have tried something post your codes so that we might help.

Hello okay let me make you understanaable about it thoug

have a lok to this website and on the left hand side you will see search filter this is what i am tring to create but have no idea so that is why i am looking for sugesstion and tutorial help though i have not started writing any code though but will do so by you guys help me out.

Member Avatar for diafol

Usually, you create the code and we give tips on that.

There are hundreds if not thousands of search scripts out there.

Filtering by word(s) will be different to filtering by category and by individual item.

Yes I know that but I am unable to find any such tutorials so that is why i posted here and tring to get idea though so i would be able to impletemnt it well i will try it using codes and if helped or got any problem will post here but would you be able to give me just an idea so i can get started??

Here is my products code

<div class="col-md-3">
        <form id="form1" name="form1" method="post" action="products.php">

        <input type="checkbox" name="string" id="string" /> Samsung
        <input type="submit" name="button" id="button" value="Filter" />

    <div class="col-md-8">

        <div class="row">
                $result = mysqli_query($connection, "select * from products");
                while ($row=mysqli_fetch_array($result)){
            <div class="prod">
                <div class="img">
                <img src="images/products/<?=$row['prod_img']?>" />

                <div class="btnbuy">
                <?php $pid = $row['serial']; ?>
                <a href='product_details.php?pid=<?php echo $pid; ?>' class="btnblue">Buy Now</a>


                <div class="ftrhead">

                <div class="descrip">        

                <div class="price">
                <p>Price: $<?=$row['product_price']?></p>

            <?php } ?>

please provide me a small idea so i can do it this is my stage of learning though i am not an expert i hope it;s not bad to learn from seniaors as I also want to become expert in php :)

Member Avatar for diafol

That's OK uk, but this is a pretty vague question, so asking for a bit of code from you will help us refine our suggestions.

Still not sure what you want to search on (filters). Let us assume that you have a list of manufacturers (from your manufacturers table):

manufacturers: id | label

Checkbox creator:

function create_checkboxes($db, $table, $idField, $labelField, $filterSuffix)
    $output = '';
    if($result = $db->query("SELECT $idField AS ccID, $labelField AS ccLABEL FROM $table ORDER BY $labelField"))
        while ($row = $result->fetch_assoc()) {
            $output .= "<label><input value='{$row['ccID']}' type='checkbox' name='filter[$filterSuffix][]' /> {$row['ccLABEL']}</label>";


Then in the appropriate place:

<form action="search.php" method="get">
    <?=create_checkboxes($mysqli, 'manufacturers', 'id', 'label', 'man')?>
    <input type="submit" name="submitFilter" value="Filter Results" />

You can then grab the checked values:

//list FK fields from which you allow filters

$allowedFilters = ['man'=>'manufacturer_id','cat'=>'category_id'];
$whereClauseItems = '';
$whereElements = [];
$where = '';

$idOptions = array(
    'options' => array(
        'min_range' => 1


    foreach($allowedFilters as $k=>$filterTable)
            foreach($_GET['filter'][$k] as $item)
                if(trim($item) && filter_var($item, FILTER_VALIDATE_INT, $idOptions)) $whereElements[$k] = intval($item);
            if(count($whereElements[$k])) $whereClauseItems[] = "`$filterTable` IN (" . implode(',',$whereElements) . ")";
    if(count($whereClauseItems[])) $where = ' ' . implode(' AND ', $whereClauseItems); //or use ' OR ' ??

$searchSQL = "SELECT ... FROM products" . $where;

//do filtered list and pass to page

This is not tested and I tried to make it as flexible as possible for searching on multiple columns - and this assumes you're passing integers to the SQL. It could be modified to present an SQL prepared statement instead - which actually would be safer.

Just a rough idea though.

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.