Welcome Guest, Not a member yet? Register   Sign In
Cannot display search result with multiple dropdown
#1

(This post was last modified: 04-24-2022, 05:53 AM by franciscaid.)

For my website I want to display search result (on a complete new page) using the parameters in the dropdown select input. I have 4 dropdowns and I tried multiple different ways to make it work. But it doesn't seem to work!

Below is my CodeIgniter 4 code:

Home Controller

The home controller file which gathers data from 4 dropdown inputs the data is fetched as an array. The array is then executed through the getSearch method located in the home model.

Code:
public function search_residential() {

    $data['getfooter'] = $this->homeModel->getFooterInfo();

    $params = array(

            'category' => $this->request->getVar('category'),
            'area' => $this->request->getVar('area'),
            'bedrooms' => $this->request->getVar('bedrooms'),
            'washrooms' =>$this->request->getVar('washrooms'), 
                     
            );

    $data['search'] = $this->homeModel->getSearch($params);   

    return view('search', $data);
}

Home Model

The home model contains the query of search.

Code:
//Searching data
public function getSearch($params) {

   
    $category = $params['category'];
    $area = $params['area'];
    $bedrooms = $params['bedrooms'];
    $washrooms = $params['washrooms'];

    $builder= $this->db->table('tblresidential');
    $builder->select('*');
    $builder->where('1 = 1');

    if ($category != '') {

        $builder->where('category', $category);

    }
    if ($area != '') {

        $builder->where('area', $area);

    }
    if ($bedrooms != '') {

        $builder->where('bedrooms', $bedrooms);

    }
    if ($washrooms != '') {

        $builder->where('washrooms', $washrooms);

    }

    $result = $builder->get();
    return $result;
   
}

HTML Code

The HTML code that is used for execution

Code:
<div class="search__area-inner">
        <?= form_open('/home/search_residential'); ?>
            <div class="row">
                <div class="col-6 col-lg-3 col-md-3">
                    <div class="form-group">
                        <select name="category" class="wide select_option">
                            <option data-display="Property Type">Property Type</option>
                            <option value="Property on sale">Property on Sale</option>
                            <option value="Property on rent">Property on Rent</option>

                        </select>
                    </div>
                </div>
                <div class="col-6 col-lg-3 col-md-3">
                    <div class="form-group">
                        <select name="area" class="wide select_option">
                            <option data-display="Select Area">Select Area</option>
                            <option value="2000">2000</option>
                            <option value="1800">1800</option>
                            <option value="1500">1500</option>
                            <option value="1200">1200</option>
                            <option value="900">900</option>
                            <option value="600">600</option>
                            <option value="300">300</option>
                            <option value="100">100</option>
                        </select>
                    </div>
                </div>
                <div class="col-6 col-lg-3 col-md-3">
                    <div class="form-group">
                        <select name="bedrooms" class="wide select_option">
                            <option data-display="Select Bedrooms">Select Bedrooms</option>
                            <option value="1 bedroom">1</option>
                            <option value="1.5 bedrooms">1.5</option>
                            <option value="2 bedrooms">2</option>
                            <option value="2.5 bedrooms">2.5</option>
                            <option value="3 bedrooms">3</option>
                            <option value="4 bedrooms">4</option>
                            <option value="5 bedrooms">5</option>
                        </select>
                    </div>
                </div>
                <div class="col-6 col-lg-3 col-md-3">
                    <div class="form-group">
                        <select name="washrooms" class="wide select_option">
                            <option data-display="Select Washrooms">Washrooms</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                        </select>
                    </div>
                </div>
                <div class="col-12">
                    <div class="form-group">
                        <button class="btn btn-primary text-uppercase btn-block"> search
                            <i class="fa fa-search ml-1"></i>
                        </button>
                    </div>
                </div>
            </div>
            <?= form_close(); ?>
        </div>

Result View (the page on which result shows)

This is the page where result shows

Code:
<?php if(!empty($search)) : ?>
<section class="residential-property-list">
        <div class="container">
        <div class="row">
        <?php foreach($search as $properties) : ?>
                <div class="col-lg-12">
                <div class="card__image card__box-v1">
                <div class="row no-gutters">
                        <div class="col-md-4 col-lg-3 col-xl-4">
                                <div class="card__image__header h-250">
                                        <a href="<?= base_url('/home/residential_property'); ?>/<?= $properties->id; ?>">
                                        <img src="<?= $properties->imageone; ?>" alt="featured-image" class="img-fluid w100 img-transition">
                                        <div class="info text-white"> for <?= $properties->category; ?></div>
                                        </a>
                                </div>
                                </div>
                                <div class="col-md-4 col-lg-6 col-xl-5 my-auto">
                                <div class="card__image-body">
                                    <h6 class="text-capitalize">
                                    <?= $properties->project; ?>
                                    </h6>
                                    <ul class="list-inline card__content">
                                        <li class="list-inline-item">
                                            <span>
                                                Bedrooms <br>
                                                <i class="fa fa-inbox"></i> <?= $properties->bedrooms; ?>
                                            </span>
                                        </li>
                                        <li class="list-inline-item">
                                            <span>
                                                Washrooms <br>
                                                <i class="fa fa-map"></i> <?= $properties->washrooms; ?>
                                            </span>
                                        </li>
                                        <li class="list-inline-item">
                                            <span>
                                                Property Facing <br>
                                                <i class="fa fa-inbox"></i> <?= $properties->facing; ?>
                                            </span>
                                        </li>
                                        <li class="list-inline-item">
                                            <span>
                                                Property area <br>
                                                <i class="fa fa-map"></i> <?= $properties->area; ?>
                                            </span>
                                        </li>
                                    </ul>
                                </div>
                                </div>
                                </div>
                                </div>

                                </div>
                <?php endforeach; ?>
        </div>
</section>
<?php else: ?>
        <br>
        <br>
        <div class="container"><h4 class="text-center">No Result Found Yet</h4></div>
        <br>
        <br>
<?php endif; ?>
Reply
#2

solved by
return $builder->get()->getResult();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB