我正在为工厂制作一个报告错误表单,但由于它们必须是动态的,因此我不得不正确布置单选按钮,因为数据是从csv文件中收集的。 csv文件如下:
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
我目前唯一真正使用的数据是问题描述和机器。我使用这两个值的原因是因为当用户点击特定的"报告错误"按钮它们将被赋予独特的选项,因为工厂中的机器往往具有不同的错误。这一切都在一个函数中处理。这是功能:
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;
}
我遇到的主要问题是我无法将错误选项放在类别标题下。编写单选按钮html很容易......
<label>
<input name="category"
type="radio"
value="<?php echo $html; ?>">
<?php echo $html; ?>
</label><br><br><br>
...在函数内部,但这意味着所有单选按钮都位于表单的顶部,而不是在&#39;类别下面。标题。
下图显示了表单的外观以及单选按钮的位置。显然,在完整版中,单选按钮将包含其中的所有值。
我听说过使用数组的建议但是我不完全确定如何实现它。我也尝试过调用该函数,但它要么没有正确返回,要么就是没有工作。
如果需要,这是我的完整代码(底部是HTML):
<!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>
摘要:我需要的是将csv文件打印在&#39;类别&#39;单选按钮形式的标题。
提前致谢。
答案 0 :(得分:1)
功能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;
}
类别输出将为:
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>
最终表格如下:(例如,如果您选择$OperationID == 20
(打孔机)
或者您的选择$OperationID == 30
(折叠机)