0

Here's an image of the errors with description: [enter image description here]

Here's the code in question

<?php 
foreach($LOCKPERIOD as $lp)
if($lpb->pay_code == $lp->pay_code){
  $ct = $lp->create_transaction;
  $dtr = $lp->d_t_r;
  $da = $lp->deduct_add_adjustment;
  $gp = $lp->generate_payslip;
  $d = $lp->date;
  $q = $this->payroll_lock_period_model->getLockPeriod($lpb->pay_code,$lp->pay_code);
  if(!empty($q)){
    $ct = $lp->create_transaction;
    $dtr = $lp->d_t_r;
    $da = $lp->deduct_add_adjustment;
    $gp = $lp->generate_payslip;
    $d = $lp->date;
  } else {
    $ct = "";
    $dtr = "";
    $da = "";
    $gp = "";
    $d = "";
  }

  if($ct == 1){
    $ct = "checked";
  }else{
    $ct = "";
  }
  if($dtr == 1){
    $dtr = "checked";
  }else{
    $dtr = "";
  }
  if($da == 1){
    $da = "checked";
  }else{
    $da = "";
  }
  if($gp == 1){
    $gp = "checked";
  }else{
    $gp = "";
  }

echo "<td align='center'><input type='checkbox'".$ct." disabled/></td>"; 
echo "<td align='center'><input type='checkbox'".$dtr." disabled/></td>"; 
echo "<td align='center'><input type='checkbox'".$da." disabled/></td>"; 
echo "<td align='center'><input type='checkbox'".$gp." disabled/></td>"; 
echo "<td align='center'>".$d."</td>";  
?>  
junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33
Nemuel
  • 11
  • 5
  • you can see the error in the image above – Nemuel Oct 02 '17 at 05:21
  • 3
    Those aren't errors, they're notices, and they have nothing to do with joining tables. You have defined $ct and $dtr inside an if()-statement, if that statement doesn't run, the $ct variable isn't set. Declare the variables outside the if (before the if) and declare them empty. If the if populates them with content... all is good. Means you can also drop the else-statements in the if/elses you have (where you set the $ct and so on to empty. – junkfoodjunkie Oct 02 '17 at 05:27
  • can you edit my codes sir? – Nemuel Oct 02 '17 at 06:46
  • The posted code does no compile. – axiac Oct 03 '17 at 12:12

2 Answers2

0

These "errors" are saying that your ct and dtr do not have any variable declared to them, which means that you are calling those without them actually being stored somewhere.

-How to fix this-

Declare your ct and dtr variables outside of the if -else. If this loop does not start, then the variables also won't be reckonized.

-Quick fix-

Declare

$ct = "";

And

$dtr = "";

Before the if loop, so they will always have a value.

I hope this helped you a bit.

Tomm
  • 1,021
  • 2
  • 14
  • 34
0

Here's a modified code that should work. However, you might need to declare those first variables outside the loop entirely, depending on whether or not the previous values has any significance.

I cleaned up a bit, changed the quotes to properly quote the HTML output, and so on.

<?php 
foreach($LOCKPERIOD as $lp)
 $ct = '';
 $dtr = '';
 $da = '';
 $gp = '';
 $d = '';

 if($lpb->pay_code == $lp->pay_code){
  $ct = $lp->create_transaction;
  $dtr = $lp->d_t_r;
  $da = $lp->deduct_add_adjustment;
  $gp = $lp->generate_payslip;
  $d = $lp->date;
  $q = $this->payroll_lock_period_model->getLockPeriod($lpb->pay_code,$lp->pay_code);

 if(!empty($q)){
   $ct = $lp->create_transaction;
   $dtr = $lp->d_t_r;
   $da = $lp->deduct_add_adjustment;
   $gp = $lp->generate_payslip;
   $d = $lp->date;
 }

  $ct = ($ct == 1) ? 'checked' : '';
  $dtr = ($dtr == 1) ? 'checked' : '';
  $da = ($da == 1) ? 'checked' : '';
  $gp = ($gp == 1) ? 'checked' : '';

  echo '<td align="center"><input type="checkbox" '.$ct.' disabled/></td>
  <td align="center"><input type="checkbox" '.$dtr.' disabled/></td>
  <td align="center"><input type="checkbox" '.$da.' disabled/></td> 
  <td align="center"><input type="checkbox" '.$gp.' disabled/></td>
  <td align="center">'.$d.'</td>';  
 ?>  
junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33