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
PHPWeb DevelopmentHTMLScripting LanguagesApache Web Server

Avatar of undefined
Last Comment
Question Mark?

8/22/2022 - Mon
Ray Paseur

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
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 :-)
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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Marco Gasi

orry, have you tried to do what I said?
Marco Gasi

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

Question Mark?

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Question Mark?

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Marco Gasi

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

Question Mark?

ASKER
Yes sir I do this as you guide me.
Question Mark?

ASKER
Thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23