2016-06-01 7 views
0

Ich mache ein Bericht Fehler Formular für eine Fabrik, aber ich bin fest auf die richtige Anordnung der Radio-Buttons, da sie dynamisch sein müssen, da die Daten aus einer CSV-Datei gesammelt werden. Die CSV-Datei ist wie folgt:Wie mache ich dynamische Radio-Buttons aus einer CSV-Datei mit der richtigen Formatierung?

Issue Type,Issue Description,Issue ID,Machine 
Program Issue,Incorrect sheet size for program,1,EM Machines 
Program Issue,Incorrect sheet thickness for program,2,EM Machines 
Program Issue,Burst and tapping is on end of program,3,EM Machines 
Program Issue,Part not tooled ,4,EM Machines 
Program Issue,Part falling out of sheet,5,EM Machines 
Program Issue,Micro join too big on part,6,EM Machines 
Program Issue,Tooled part bursting but not tapping,7,EM Machines 
Program Issue,Uneven QTY of parts that have a left and right on sheet,8,EM Machines 
Program Issue,Excessive QTY on sheet,9,EM Machines 
Program Issue,Incorrect 'C' station selected,10,EM Machines 
Program Issue,No drawing attached to file,11,EM Machines 
Machine Issues,Blunt tool,12,EM Machines 
Machine Issues,Damaged tool,13,EM Machines 
Program Issue,No drawing attached to file,14,Pressbrake 
Program Issue,No overall length indicated in drawing,15,Pressbrake 

Die einzigen Daten, die ich wirklich im Moment bin mit der Beschreibung des Problems und die Maschine. Der Grund, warum ich diese beiden Werte verwende, liegt darin, dass der Benutzer, wenn er auf eine bestimmte Schaltfläche "Fehler melden" klickt, einzigartige Optionen erhält, da die Maschinen in der Fabrik normalerweise unterschiedliche Fehler aufweisen. Dies alles wird in einer Funktion behandelt. Hier ist die Funktion:

function customErr ($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      {  
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

Das Hauptproblem, das ich habe, ist, dass ich die Fehleroptionen nicht erhalten kann, um unter dem Kategorietitel zu gehen. Es ist leicht genug, um den Radio-Button html zu schreiben ...

<label> 
<input name="category" 
type="radio" 
value="<?php echo $html; ?>"> 
<?php echo $html; ?> 
</label><br><br><br> 

... innerhalb der Funktion aber dies bedeutet, dass alle Radiobuttons am oberen Rand des Formulars sein wird und nicht unter der ‚Kategorie‘ title .

Das Bild unten zeigt, wie das Formular aussieht und wo die Radio-Buttons sein sollen. Offensichtlich werden in der vollständigen Version die Radiobuttons alle Werte enthalten.

enter image description here

Ich habe Vorschläge zur Verwendung eines Arrays gehört jedoch bin ich nicht ganz sicher, wie das realisieren. Ich habe auch versucht, die Funktion aufzurufen, aber es ist entweder nicht richtig zurück oder funktioniert einfach nicht.

Hier ist meine vollständige Code, wenn Sie (am unteren Rand HTML) wollen:

<!DOCTYPE HTML> 
<html> 
<head> 
<link rel="stylesheet" type="text/css" href="/css/main_style.css"> 
<style> 
.error {color: #FF0000;} 
table, th, td {border: 1px solid white;} 
</style> 
</head> 
<body> 
<script> 
function close_window() { 
    close(); 
} 
</script> 
<?php 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
include("includes/classes.php"); 
include("includes/classes_monitoring.php"); 
$link = open_v8_db(); 
$users = get_clocked_in_users(); 
$OperationID = @$_REQUEST['OperationID']; 

$title = ""; 
$grayedOut = false; 
$disabledInput = ""; 
$hiddenJobDiv = ""; 
$hiddenPartDiv = ""; 
$ID = ""; 
$html = ""; 

$jobid = @$_REQUEST['JobID']; 
$part_id = @$_REQUEST['PartID']; 
$machCode = @$_REQUEST['Machine']; 

if ($OperationID == 20) 
{ 
    customErr($OperationID); 
    $title = "Punching Machine"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 30) 
{ 
    customErr($OperationID); 
    $title = "Folding Machine"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 40 || $OperationID == 140) 
{ 
    $title = "Powder Coating"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 50 || $OperationID == 150) 
{ 
    $title = "Assembly"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 60 || $OperationID == 160) 
{ 
    $title = "Inspection"; 
    $grayedOut = true; 
} 
elseif ($jobid != "" && $part_id == "") 
{ 
    $title = "Job"; 
} 
else 
{ 
    $title = "General"; 
    $grayedOut = false; 
} 

if ($greyedOut = true) 
{ 
    $disabledInput = "readonly"; 
} 

function customErr ($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      {  
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

$jobErr = $partErr = $machErr = ""; 
$job = $part = $mach = $note = ""; 

if ($jobid == "") 
{ 
    $hiddenJobDiv = "style=\"display:none;"; 
} 
if ($part_id == "") 
{ 
    $hiddenPartDiv = "style=\"display:none;"; 
} 

function test_input($data) 
{ 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
} 
?> 
<div class="reportForm"> 
    <h2>Report <u><?php echo $title; ?></u> Error</h2> 
    <form action="send_form_email.php?OperationID=<?php print ($OperationID) ?>&title=<?php print ($title) ?>" method="post"> 
     <table> 
     <tr> 
      <td>Name:</td> 
       <td> 
       <select name="users"> 
       <?php 
       foreach($users as $key => $value){ 
        echo "<option value=\"$key\">$key</option>"; 
       } 
       ?> 
       </select> 
       </td> 
     </tr> 
     <tr> 
      <td <?php print $hiddenJobDiv ?>>Job Number:</td> <td><input type="text" name="jobid" value="<?php print ($jobid) ?>" <?php print $disabledInput ?>></td> 
     </tr> 
     <tr> 
      <td <?php print $hiddenPartDiv ?>>Part Number:</td> <td><input type="text" name="partid" value="<?php print ($part_id) ?>" <?php print $disabledInput ?>></td> 
     </tr> 
      <?php if ($OperationID == 20){ ?> 
      <tr> 
       <td>Machine:</td> <td><input type="text" name="mach" value="<?php print ($machCode) ?>" <?php print $disabledInput ?>></td> 
      <tr> 
      <?php } ?> 
     </table><br> 
     Category:<br><br><br> 
     <?php 
     $html .= customErr($ID); 
     ?> 
     <label> 
     <input name="category" 
     type="radio" 
     value="<?php echo $html; ?>"> 
     <?php echo $html; ?> 
     </label><br><br><br> 
     <?php 
     /* 
         ?> 
         <label> 
         <input name="category" 
         type="radio" 
         value="<?php echo $line_of_text[1]; ?>"> 
         <?php echo $line_of_text[1]; ?> 
         </label><br><br><br> 
         <?php 
     */ 
     ?> 
      <label> 
      <input name="category" type="radio" value="Other" checked>Other 
      </label><br><br><br> 
     Note:<br> <textarea name="comment" rows="10" cols="70" placeholder="More detail... (Is there a way to recreate the error? What happened?)"></textarea> 
     <br><br> 
     <input type="submit" name="submit" value="Submit" class="userFriendly"> 
     <a href="#" onclick="close_window();return false;"><input type="submit" name="close" value="Close" class="userFriendly"></a> 
    </form> 
</div> 
</body> 
</html> 

Zusammenfassung: Was ich brauche, ist die CSV-Datei zu haben, unter der ‚Kategorie‘ Titel in Radio-Button werden ausgedruckt bilden.

Vielen Dank im Voraus.

Antwort

1

Die Funktion customErr($ID):

function customErr($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      { 
       $html[] = $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html[] = $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

Und die Kategorie Ausgang wird sein:

Category:<br><br><br> 
     <?php 
     $html = customErr($OperationID); 
     foreach ($html as $oneError):?> 
     <label> 
      <input name="category" 
        type="radio" 
        value="<?php echo $oneError; ?>"> 
      <?php echo $oneError; ?> 
     </label><br> 
     <?endforeach;?> 
     <label> 
      <input name="category" type="radio" value="Other" checked>Other 
     </label><br><br><br> 

Endform wie folgt aussieht: (wenn Ihr choise $OperationID == 20 (Stanzmaschine) zum Beispiel) enter image description here

oder wenn Ihre Wahl $OperationID == 30 (Falzmaschine)

enter image description here

+0

Dank dumkaaa. Nicht mit den Dateien im Moment an meinem Computer. Sieht vielversprechend aus. Ich sag dir, wie es geht. – Moms

+0

Funktioniert fantastisch. Vielen Dank. – Moms

Verwandte Themen