1

I am having frustration because of this error. When I am still programming php without using any framework my code is ok but when I transferred it in codeigniter, it always says severity undefined functions. Please check my posted code:

foreach($data['employee'] as $val)
    {
        if($val['Active']==0)
        {
            $status = @strtoupper('Resigned');
        }
        else
        {
            $status = @strtoupper('Active');
        }

        $str = @substr($val['WS_Code'],0,-2);
        if($str == "PR")
        {
            $line = @substr($val['WS_Code'],0,-1);
            $str2 = @substr($val['WS_Code'],-1);
            if($str2 == 'B')
            {
                $section = "BRIEF";
            }
            else
            {
                $section = "PANTY";
            }

        }
        elseif($str == "SP")
        {
            $line = @substr($val['WS_Code'],0,-1);
            $str2 = @substr($val['WS_Code'],-1);
            if($str2 == "B")
            {
                $section = "BRIEF";
            }
            else
            {
                $section = "PANTY";
            }
        }
        elseif($str == "BL")
        {
            $section = "BRIEF";
            $str2 = @substr($str,-3,2);
            $line = $str2;
        }
        elseif($str == "PL")
        {
            $section = "PANTY";
            $str2 = @substr($str,-3,2);
            $line = $str2;
        }

And here is the rest of the code and how I use it:

<tr>
   <td><label class='control-label'>Section:</label></td>
   <td>
      <select class='form-control' name='cmbsection' id='cmbsection'>
         <option value='".$section."'>".$section."</option>
         ";
         $section_code = array();
         $section_code[] = $section;
         foreach($data['sectionlist'] as $value)
         {
         if(!in_array($value['sectionName'],$section_code))
         {
         echo "<option value='".$value['sectionName']."'>".$value['sectionName']."</option>";
         }
         }
         echo "
      </select>
   </td>
   <td><label class='control-label'>Line:</label></td>
   <td>
      <select class='form-control' name='cmbline' id='cmbline'>
         ";
         $line_code = array();
         $line_code[] = $line;
         echo "
         <option value='$line'>$line</option>
         ";
         foreach($data['linelist'] as $value)
         {
         if(!in_array($value['lineName'],$line_code))
         {
         echo "<option value='".$value['lineName']."'>".$value['lineName']."</option>";
         }
         }
         echo "
      </select>
   </td>
</tr>

Please note that I am echoing a table inside the controller and the error always points the $section and$line in the if(!in_array($value['lineName'],$line_code)) code.

enter image description here

enter image description here

12
  • You better read more about the mvc and Codeigniter. Echoing inside controller is a bad practice. Commented Apr 18, 2016 at 9:55
  • Please mention in which lines you are getting this error? Commented Apr 18, 2016 at 9:58
  • I don't want to use json so much that's why I am doing it like this and also I don't know if my code logic will work if echo json.... Commented Apr 18, 2016 at 9:59
  • its in the if(!in_array($value['lineName'],$line_code)) line for $line and same in if(!in_array($value['sectionName'],$section_code)) for $section... Commented Apr 18, 2016 at 9:59
  • Turn on error processing in the environment that is not reporting any error and you will probably see errors in both environments error_reporting(E_ALL); ini_set('display_errors', 1); Commented Apr 18, 2016 at 10:02

2 Answers 2

2

I would not call this a good solution but it will at least ensure that the variables $line and $section exist.

Your problem is that you are getting a code in WS_Code that you are not processing. As you only create the 2 variables if you see a code you have coded for, it must be that you have a new code that you had not expected and coded for.

The proper solution would be to work out what WS_Code you are getting in this code that you are not expecting.

In fact the proper solution would be to create a table that contains a code and a full_desc that you can query in order to expand these codes into whatever full description you want to use, and ensure that when a new code is created the table get updated accordingly

$line = 'new unexpected code recieved';
$section = 'new unexpected section recieved';

foreach($data['employee'] as $val)
    {
        if($val['Active']==0) {
            $status = strtoupper('Resigned');
        } else {
            $status = strtoupper('Active');
        }

        $str = substr($val['WS_Code'],0,-2);
        if($str == "PR") {
            $line = substr($val['WS_Code'],0,-1);
            $str2 = substr($val['WS_Code'],-1);
            if($str2 == 'B') {
                $section = "BRIEF";
            } else {
                $section = "PANTY";
            }

        }
        elseif($str == "SP") {
            $line = substr($val['WS_Code'],0,-1);
            $str2 = substr($val['WS_Code'],-1);
            if($str2 == "B") {
                $section = "BRIEF";
            } else {
                $section = "PANTY";
            }
        }
        elseif($str == "BL") {
            $section = "BRIEF";
            $str2 = substr($str,-3,2);
            $line = $str2;
        }
        elseif($str == "PL") {
            $section = "PANTY";
            $str2 = substr($str,-3,2);
            $line = $str2;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

what the......! I didn't know that I should still need to declare it at the top of foreach before using the variables. I thought codeigniter will not require me anymore of doing it but thanks you woke me up from my dumbness.....
-1

Please use the following code:

if(isset($line)){
   echo "<option value='$line'>$line</option>";
}

foreach($data['linelist'] as $value){
    if(isset($value['lineName']) && isset($line_code)) {
        if (!in_array($value['lineName'], $line_code)) {
            echo "<option value='" . $value['lineName'] . "'>" . $value['lineName'] . "</option>";
       }
   }
}

2 Comments

sorry but the code you gave was not in the line that suggest the errors please check the image that I posted.....
Again that just ignoring the error made in the code that assigns a name to $line based on the code to full name processing, which is defective

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.