Link to home
Start Free TrialLog in
Avatar of Question Mark?
Question Mark?Flag for India

asked on

codginator search query

I want to make search query(codginator)from select box mean when i push submit button filter do his work .

but this giving me error.

Undefined variable: dt
Undefined variable: val

Invalid argument supplied for foreach()

IF ANY ONE CAN PLEASE GUIDE WHERE I M WRONG.
model.php
controler.php
VIEW.php
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

You cannot rely on undefined variables in PHP.  You must test to see if they exist and contain useful values before you use them in a script.
http://php.net/manual/en/function.isset.php

In case you're new to PHP and want to get a foundation (necessary for working on PHP internals of CodeIgniter or any other framework) this article might help.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Avatar of Marco Gasi
I think you get that error when you load the page before to submit your query: this means that the chek

if($this->input->post('submit'))

fails and then the variable $dt['val'] is never filled and when the view is loaded it raises the error. Put a check in the View:

<?php 
if (isset($val))
{
foreach ($val as $va){?>
<?php echo  $va['namehost'];?><br>
<?php  }
}?>

Open in new window



And the error will go away :-)
Avatar of Question Mark?

ASKER

THANKS SIR ,
  FOR YOUR SUPPORT BUT I THINK THAT I M MAKING PROBLEM MOST ON
MODEL (I THINK THATS NOT EXACT QUERY AS CI WANT)
THEN SMALL ON CONTROLLER.
orry, have you tried to do what I said?
About your model, here you'll find the info you need:https://ellislab.com/codeigniter/user-guide/database/active_record.html


 public function mgetclinds($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)
    {
         $array = array(
              'state' => $f,
              'city' => $g,
              'area' => $h, 
              'cate' => $i,
              'for' => $j
         );
        $this->db->like($array);
        $query=$this->db->get($a,$b,$c,$d,$e);
        return $query->result_array();
    }?>

Open in new window

Oh sorry
yes sir i apply checck method from this 2 error are gone

but after pushing submit button

these error are come

* all errors on same page

really thanks sir that you are helping me.
error1.png
error2.png
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I strongly discourage you from hiding errors, warnings and even notices: if there is an issue, then solve it now. Hiding it just grant you to accumulate an incredible amount of small issues which, all together, can make your life a nightmare.
That error is probably because the creation of $dt variable depends on the submission of values. If the user doesn't submit anything, that is if you access the page directly typing in the adddress bar of your browser www.yourdomain.com/controller_name/extra1, then the $dt array doesn't exsist, but you pass it to the view anyway: from here the warning. Do this instead:
<?php  //ON CONTROLLER//
public function extra1()
        {
          $dt['val'] = '';
          if($this->input->post('submit'))
                {
                    $selected1=$this->input->post('state');
                    $selected2=$this->input->post('city');
                    $selected3=$this->input->post('area');
                    $selected4=$this->input->post('cate');
                    $selected5=$this->input->post('for');
         
        
        $dt['val']=$this->demomod->mgetclinds('reg',$selected1,$selected2,$selected3,$selected4,$selected5);
          // echo "$selected1,$selected2,$selected3,$selected4,$selected5";
   
          }  
            
          $this->load->view('extra1',$dt); 

       }
    ?> 

Open in new window

Yes sir I do this as you guide me.
Thanks.