Mark Alan
Mark Alan

Reputation: 455

Multi step search is not working in codeigniter

I have created a multi level search using codigniter I have used Like active records to do so but I don't know why it is not working let suppose if i search something and echo the keywords and match it with database yes they are matching but I don't know why the sql is returning 0 records to be found from the database

Php code

$position = $this->session->set_userdata('position', $this->input->post('position'));
                $adress_all = explode(",", $this->session->userdata('address'));
                $keyword = array(
                    'address'   => $adress_all[0],
                    'game'      => $this->session->userdata('skills'),
                    'gender'    => $this->session->userdata('coach'),
                    'Positions' => $this->session->userdata('position')
                );

                print_r($keyword);
                $sql = $this->db->like($keyword);
                $sql = $this->db->get_where('coach', array('type' => 'private'));

Html Form

<!--Step 1 -->
<form action="<?php echo base_url() . "home/main?st=step1" ; ?>" method="POST">
                <ul>
                    <li><input type="text" placeholder="Categoría" name="skills" id="skills" onkeyup="autocomp();" />
                        <ul id="resultkeyword"></ul>
                    </li>   
                    <li><input id="geocomplete" type="text" name="address" placeholder="Código Postal" size="90" /></li>
                    <li><button type="submit" class="cutter-btn" name="process">Buscar<span><i class="fa fa-angle-right" aria-hidden="true"></i></span></button></li>
                </ul>
            </form>

         <!--Step 2-->
                <form action="<?php echo base_url() . "home/main?st=step2" ; ?>" method="POST" class="step-form">
                    <h3>Preferred gender of your coach:</h3>
                    <div class="form-group">
                    <div>
                      <input id="radio1" type="radio" name="coach" value="" checked="checked"><label for="radio1">No Preference</label>
                    </div>
                    <div>
                      <input id="radio2" type="radio" name="coach" value="Male"><label for="radio2">Only Show Male</label>
                    </div>
                    <div>
                      <input id="radio3" type="radio" name="coach" value="Female"><label for="radio3">Only Show Female</label>
                    </div>
                    </div>

                    <a href="<?php echo base_url() . "home/main" ; ?>" class="nxt-step"><i class="fa fa-angle-double-left" aria-hidden="true"></i> Previous</a>
                    <button type="submit" class="nxt-step">Next <i class="fa fa-angle-double-right" aria-hidden="true"></i></button>

                </form>

<?php 
    $session_data = array(
        'country' => $this->input->post('country'),
        'coach'   => $this->input->post('coach')
    );
    $this->session->set_userdata($session_data);
?>
    <!-- STEP 3 -->
                <form action="<?php echo base_url() . "home/listings" ; ?>" method="POST" class="step-form">
                    <h3>What position?</h3>
                    <div class="form-group">
                    <div>
                      <input id="posotion1" type="radio" name="position" value="Not Sure" checked="checked"><label for="posotion1">Not Sure</label>
                    </div>
                    <div>
                      <input id="posotion2" type="radio" name="position" value="Guard"><label for="posotion2">Guard</label>
                    </div>
                    <div>
                      <input id="posotion3" type="radio" name="position" value="Forward"><label for="posotion3">Forward</label>
                    </div>
                    <div>
                      <input id="posotion4" type="radio" name="position" value="Center"><label for="posotion4">Center</label>
                    </div>
                    </div>

                    <a href="<?php echo base_url() . "home/main?st=step2" ; ?>" class="nxt-step"><i class="fa fa-angle-double-left" aria-hidden="true"></i> Previous</a>
                    <button type="submit" class="nxt-step">Next <i class="fa fa-angle-double-right" aria-hidden="true"></i></button>

                </form>
    <!-- END STEP 3 -->    

Here is the result for print_r Array ( [address] => 2707 Broadway [game] => Basketball [gender] => Male [Positions] => Guard )

Database values address : 2707 Broadway game : Basketball gender : Male Positions : Guard, Forward, Back

If I comment all 3 except any 1 of them then I got result but if all 4 array are uncommented then I am not getting any result means if I am passing only 1 value then sql is returning rows but if there are more then 1 then the sql is returning 0 rows I mean to say the key values are matching then why it is giving me 0 result in return ?

Upvotes: 0

Views: 80

Answers (1)

Saty
Saty

Reputation: 22532

You can use or_like method to search in multiple column

$this->db->like('address', $adress_all[0]);
$this->db->or_like('game', $this->session->userdata('skills'));
$this->db->or_like('gender', $this->session->userdata('coach'));
$this->db->or_like('Positions', $this->session->userdata('position'));
$sql = $this->db->get_where('coach', array('type' => 'private'));

Upvotes: 0

Related Questions