下面的代码是一个相当复杂的函数(display_analysis();
),其中另一个函数(analysis_column();
)具有多个变量。我承认我的无知为什么应该或不应该这样做。我知道有很多变量可能会导致问题,并且嵌套的php函数并不理想,但是我只需要对当前问题提出一些建议,即analysis_column();
函数无法正常工作。
第一个功能display_analyses();
:
function display_analyses($analysis_type) {
require 'dbh.php';
global $order_id;
$query = "SELECT * FROM analysis_database JOIN microbiology_analysis_database ON analysis_database.m_analysis_id=microbiology_analysis_database.id WHERE order_id=$order_id AND analysis_database.analysis_type='$analysis_type';";
$result = mysqli_query($conn, $query);
$analysis_prepared = '';
$prepared_by = '';
$step_1 = '';
$step_2 = '';
$step_3 = '';
$step_4 = '';
$step_5 = '';
$step_6 = '';
$step_7 = '';
$step_8 = '';
$step_9 = '';
$output = '';
$output .= '
<thead>
<tr>
<th colspan="1"></th>
<th width="10%">Analysis</th>
<th width="20%">Step 1</th>
<th width="20%">Step 2</th>
<th width="20%">Step 3</th>
<th width="20%">Step 4</th>
<th width="20%">Final Step</th>
</tr>
</thead>
<tbody>';
while ($row = mysqli_fetch_assoc($result)) {
$output .=
'<tr>
<td>
<input class="hidden" name="m_analysis_id" id="m_analysis_id" value="'.$row['analysis_id'].'" readonly>
<input class="hidden" name="order_id" id="order_id" value="'.$row['order_id'].'" readonly></td>
<td>'.$row['analysis_name'].'</td>';
analysis_column(1);
analysis_column(2);
analysis_column(3);
analysis_column(4);
if ($row['step_10'] == '') {
$output .= '<td></td>';
} elseif ($row['step_10_progress'] == 'Completed') {
$analyst_single = $row['step_10_analyst'];
$sql3 = "SELECT * FROM employee_database WHERE id=$analyst_single";
$result3 = mysqli_query($conn, $sql3);
$input3 = mysqli_fetch_assoc($result3);
$output .= '<td style="color:green;"><form class="analysis_progress">
<input class="hidden analysis_number" name="analysis_number" value="10">
<input class="hidden analysis_id" name="analysis_id" value="'.$row['analysis_id'].'" readonly>
<input title="Analyst: '.$input3['first_name'].' '.$input3['last_name'].' ('.$row['step_10_date'].' | '.$row['step_10_time'].')" name="step_number" class="step_10 analysis_progress_check" type="checkbox" checked disabled>'.$row['step_10'].'<br><em>'.$input3['first_name'].' '.$input3['last_name'].'</em></form></td>';
} else {
$output .= '<td><form class="analysis_progress">
<input class="hidden" name="m_analysis_id" value="'.$row['m_analysis_id'].'">
<input class="hidden analysis_number" name="analysis_number" value="10">
<input class="hidden analysis_id" name="analysis_id" value="'.$row['analysis_id'].'" readonly>
<input title="Analysis Pending" name="step_number" class="step_10 analysis_progress_check" type="checkbox">'.$row['step_10'].'</form></td>';
}
}
$output .= '</tbody>';
echo $output;
}
第二个函数analysis_column();
:
function analysis_column($number) {
require 'dbh.php';
global $output;
global $row;
global $order_id;
if ($row['step_'.$number] == '') {
$output .= '<td></td>';
} elseif ($row['step_'.$number.'_progress'] == 'Completed') {
$analyst_single = $row['step_'.$number.'_analyst'];
$sql3 = "SELECT * FROM employee_database WHERE id=$analyst_single";
$result3 = mysqli_query($conn, $sql3);
$input3 = mysqli_fetch_assoc($result3);
$output .= '<td style="color:green;"><form>
<input class="hidden" name="order_id" value="'.$order_id.'">
<input class="hidden analysis_number" name="this_analysis_number" value="'.$number.'">
<input class="hidden" name="order_id" value="'.$order_id.'">
<input class="hidden" name="m_analysis_id" value="'.$row['m_analysis_id'].'">
<input class="hidden analysis_id" name="analysis_id" value="'.$row['analysis_id'].'" readonly>
<input name="step_number" class="step_'.$number.' analysis_progress_check" type="checkbox" checked disabled>'.$row['step_'.$number].'<br><em>'.$input3['first_name'].' '.$input3['last_name'].'</em> | <i class="completed_analysis_link fas fa-info"></form></i></td>';
} else {
$output .= '<td><form id="analysis_form" class="analysis_progress">
<input class="hidden" name="order_id" value="'.$order_id.'">
<input class="hidden" name="m_analysis_id" value="'.$row['m_analysis_id'].'">
<input class="hidden analysis_number" name="analysis_number" value="'.$number.'">
<input class="hidden analysis_id" name="analysis_id" value="'.$row['analysis_id'].'" readonly>
<input title="Analysis Pending" name="step_number" class="step_'.$number.' analysis_progress_check" type="checkbox">'.$row['step_'.$number].'';
if ($row['step_'.$number.'_duration'] != '') {
$output .= '
<input class="hidden" name="duration_'.$number.'" value="'.$row['step_'.$number.'_duration'].'" readonly>
<input title="Step Duration" value="Step duration: '.$row['step_'.$number.'_duration'].' (hh:mm)" placeholder="Step duration: '.$row['step_'.$number.'_duration'].' (hh:mm)" readonly>';
} if ($row['step_'.$number.'_date_prev'] == 'Yes') {
$output .= '<input title="Enter an additional date to the step" name="date_prev_'.$number.'" type="date" value="">';
} if ($row['step_'.$number.'_storage'] == 'Yes') {
$sql4 = "SELECT * FROM storage_database WHERE storage_type='cold_store';";
$result4 = mysqli_query($conn, $sql4);
$output .= '
<input title="Select a storage location for this step" name="storage_location_'.$number.'" placeholder="Select a Storage Location" list="storage_location_list">
<datalist id="storage_location_list">';
while ($row2 = mysqli_fetch_assoc($result4)) {
$output .= '<option>'.$row2['storage_name'].' <em>('.$row2['storage_temp'].' ℃)</em></option>';
}
$output .= '</datalist>';
} if ($row['step_'.$number.'_incubation'] == 'Yes') {
$sql5 = "SELECT * FROM storage_database WHERE storage_type='incubator';";
$result5 = mysqli_query($conn, $sql5);
$output .= '
<input title="Select a incubator for this step" name="incubation_'.$number.'" placeholder="Select a Incubator" list="incubation_list">
<datalist id="incubation_list">';
while ($row3 = mysqli_fetch_assoc($result5)) {
$output .= '<option>'.$row3['storage_name'].' <em>('.$row3['storage_temp'].' ℃)</em>';
}
$output .= '</datalist>';
} if ($row['step_'.$number.'_input'] == 'Yes') {
$output .= '<input title="Input some additional step information..." name="ex_input_'.$number.'" placeholder="Input some additional step information..." value="">';
}
$output .= '</form></td>';
}
}
这是函数的初始调用位置:
if (isset($_GET['display_analyses'])) {
$order_id = $_GET['display_analyses'];
if ($_GET['analysis_type'] == 'Microbiological') {
display_analyses('Microbiological');
} elseif ($_GET['analysis_type'] == 'Chemical') {
display_analyses('Chemical');
}
}
同样,我知道我的php脚本编制方法需要工作,尽管我只需要解决函数问题,但我应该使用准备好的语句。