Undefined variable in function with query

Posted 1 year ago by paklic9

Hi, I have problem with my function, error is: "Undefined variable: filtry". I know why, the variable $filtry have to be defined in query function (like variable $j is), then it is working. But I cannot have this variable static, because variable $filtry will be always diffrent, so I need set it before function, then call it in function. Is it possible?

Thanks in advance for help.

My function:

function dbselect($tabulka, $filtry){
  $inzerce = \DB::table($tabulka)
      $j = 0;
      foreach ($filtry as $filtr) {
      $filtr = \Request::has($filtr) ? \Request::get($filtr) : [];
          $i = 0;
          foreach ($filtr as $polozka) {
            if ($i == 0) {
              $query->where($filtry[$j],'=', $polozka);
            $query->orwhere($filtry[$j],'=', $polozka);

Calling function:

$filtry = ['kategorie'];
dbselect('zviratas', $filtry);

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.