我正在爲工廠製作一個報表錯誤表單,但我堅持正確地佈置單選按鈕,因爲它們必須是動態的,因爲數據是從csv文件收集的。 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>
...裏面的功能然而,這意味着所有單選按鈕將在窗體頂部,而不是下的「類別」稱號。
下圖顯示了表單的外觀以及單選按鈕的位置。很明顯,在完整版本中,單選按鈕將包含所有值。
我聽說過使用數組的建議,但我不能完全確定如何實現這一點。我也嘗試過調用函數,但它要麼不能正確地返回,要麼就不起作用。
這裏是我完整的代碼,如果你想要的(在底部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文件要在單選按鈕下的「類別」標題打印出來形成。
在此先感謝。
感謝dumkaaa。目前不在我的電腦上。看起來很有希望。我讓你知道它是怎麼回事。 – Moms
奇妙地工作。非常感謝你。 – Moms