Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PHP Fix the bug in my code, My code is below the question. Here is the question:

ID: 641024 • Letter: P

Question

PHP Fix the bug in my code, My code is below the question.

Here is the question:

Here is the code I have so far!

//input file employeeID employeeName EmployeeWages
$mm = array(); // not important input
$row = 0; // not important input
$recordCount = 0;
$employeeID = 0;
$employeeName = "";
$employeeWage = 0;
$found = 0;
$ifa = 0;
$fmm = fopen("tits.txt", "r") or die("No Dice broham!");
//read record
fscanf($fmm, "%d%s%d", $mm[$r][0], $mm[$r][1],$mm[$r][2]);

//read?
while(!feof($fmm))
{

$r++;
fscanf($fmm, "%s%s%s%d", $mm[$r][0], $mm[$r][1],$mm[$r][2],$mm[$r][3]);
}
fclose($fmm);
$recordCount = $r;

//printf(" %d", $recordCount);


printf(" Enter the employeeID or (0) To Exit: ");
fscanf(STDIN, "%d", $employeeID);
while($employeeID != "0")
{
$r = 0;
$found = 0;
while( $r < $recordCount AND $found == 0)
{
if($employeeID == $mm[$r][0])
{
$found = 1;
$ifa = $r;
}

$r++;
}
if($found != 0)
{
printf( " EmployeeID: %-7d NAME: %s SALARY: %d", $mm[$ifa ][0], $mm[$ifa ][1],$mm[$ifa ][2],$mm[$ifa ][3]);
}
else
{
printf(" WE COULDNT FIND HIM BRO HES A MAGICIAN");

}
printf(" Enter the employeeID or (0) To Exit: ");
fscanf(STDIN, "%s", $employeeID);
}

//fscanf(STDIN, "%s", $buster);

?>

Explanation / Answer

<?php
//input file employeeID employeeName EmployeeWages
$mm = array(); // not important input
$row = 0; // not important input
$recordCount = 0;
$employeeID = 0;
$employeeName = "";
$employeeWage = 0;
$found = 0;
$ifa = 0;
$r=0;// not defined earlier
$fmm = fopen("tits.txt", "r") or die("No Dice broham!");
//read record
fscanf($fmm, "%d%s%d", $mm[$r][0], $mm[$r][1],$mm[$r][2]);

//read?
while(!feof($fmm))
{

$r++;
fscanf($fmm, "%s%s%s%d", $mm[$r][0], $mm[$r][1],$mm[$r][2],$mm[$r][3]);
}
fclose($fmm);
//print_r($mm);

$fmm=fopen("php://stdin","r"); //open our file pointer to read from stdin
$recordCount = $r;
//printf(" %d", $recordCount);
printf(" Enter the employeeID or (0) To Exit: ");
fscanf($fmm, "%d", $employeeID); //use fle pointer

while($employeeID != "0")
{
   $r = 0;
   $found = 0;
   while( $r < $recordCount AND $found == 0)
   {
       if($employeeID == $mm[$r][0])
       {
           $found = 1;
           $ifa = $r;
       }
       $r++;
   }
   if($found != 0)
   {
       printf( " EmployeeID: %-7d NAME: %s SALARY: %d", $mm[$ifa ][0], $mm[$ifa ][1],$mm[$ifa ][2]); //$mm[$ifa][2] not need we have only three column
   }
   else
   {
       printf(" WE COULDNT FIND HIM BRO HES A MAGICIAN");

   }
   printf(" Enter the employeeID or (0) To Exit: ");
   fscanf($fmm, "%s", $employeeID); // use file pointer
}
fclose($fmm); // close the file pointer
?>