codginator search query

Question Mark?
Question Mark? used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Marco GasiFreelancer
Top Expert 2010

Commented:
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 :-)

Author

Commented:
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.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Marco GasiFreelancer
Top Expert 2010

Commented:
orry, have you tried to do what I said?
Marco GasiFreelancer
Top Expert 2010

Commented:
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

Author

Commented:
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
Freelancer
Top Expert 2010
Commented:
Ok, I'd have to look at your code with more attention. It is inconsistent. Look at this: your model method accept 10 parameters
public function mgetclinds($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)

Open in new window

but you pas it just 6
$dt['val']=$this->demomod->mgetclinds('reg',$selected1,$selected2,$selected3,$selected4,$selected5);

Open in new window

And 'reg' param what is? It is never used in model method so it is uneeded.
Let's summarize: you want look for records which have area, city, state etc LIKE the ones submitted by the user, right? Okay rewrite code this way and see if it makes sense:

Controller:
<?php  //ON CONTROLLER//
public function extra1()
        {
          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($selected1,$selected2,$selected3,$selected4,$selected5);
          }  
            
          $this->load->view('extra1',$dt); 

       }
    ?> 

Open in new window


Model:
 public function mgetclinds($state,$city,$area,$cate,$for)
    {
         $array = array(
              'state' => $state,
              'city' => $city,
              'area' => $area, 
              'cate' => $cate,
              'for' => $for
         );
        $this->db->like($array);
        $query=$this->db->get('city', 'state', 'area', 'cate', 'for');
        return $query->result_array();
    }?>

Open in new window

I don't grant this one work, but it's more consistent. Notice I've used significant names for variables: it's a superflous diffculty to use meaningless letters: if you type a bit more, you can live better whean you have to debug your code :-)
THANKS SIR
FOR YOUR GREAT CONTRIBUTION. THIS WILL SOLVED MY PROBLEM.

BUT THERE IS AN (ERROR OF UNDEFINED VARIABLE dt.)
SO I HIDE THIS FROM Error Reporting (0).

THEN THIS IS MUCH FOR ME THAT NOW RESULTS ARE COMING.

AGAIN thanks SIR.
UNDEFINED-VARIABLE.png
Marco GasiFreelancer
Top Expert 2010

Commented:
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

Author

Commented:
Yes sir I do this as you guide me.

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial