php - No Data & No Error when using function inside IF Statement -


i having trouble getting php script work when using function in if statements.

the code runs, doesn't give me information, nor errors, if remove if's works fine, project working on, essential.

here code - have took out sql save space..

if ($var === 'pk%') {       cdb::usedb('blah', 'blah', 'blah', 'blah');     $sql = "blah blah             ";      $lrs = cdb::executequery($sql);      if ($lrs) {         $jsondata = convert($lrs);          function convert($lrs)         {             // re-get variable can't outside of function             $var = $_get['variable'];             $intermediate = array();             while ($vals = cdb::getassoc($lrs)) {                 $key = $vals['var'];                 $y = $vals['measure_1'];                 if (!isset($intermediate[$key])) $intermediate[$key] = array();                 $intermediate[$key][] = array('x' => count($intermediate[$key]), 'y' => $y);               }               $output = array();              foreach ($intermediate $key => $values) {                 $output[] = array(                     "key" => $key,                     'values' => $values                 );             }              return json_encode($output, json_numeric_check);           }      } } 

can shed light on doing wrong?

you defining function in conditional way. in case definition must processed prior being called.

i recommend declaring function separately , use it, like:

function convert($lrs) {     // re-get variable can't outside of function     $var = $_get['variable'];     $intermediate = array();      while ($vals = cdb::getassoc($lrs)) {         $key = $vals['var'];         $y = $vals['measure_1'];         if (!isset($intermediate[$key])) $intermediate[$key] = array();             $intermediate[$key][] = array('x' => count($intermediate[$key]), 'y' => $y);     }       $output = array();      foreach ($intermediate $key => $values) {         $output[] = array(             "key" => $key,             'values' => $values         );     }          return json_encode($output, json_numeric_check); }  if ($var === 'pk%') {     cdb::usedb('blah', 'blah', 'blah', 'blah');     $sql = "blah blah";      $lrs = cdb::executequery($sql);      if ($lrs) {         $jsondata = convert($lrs);     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -