示例我创建了一个用户界面,该界面显示一个包含文件夹路径的数据库。然后用户选择要打开的路径并发送到search.php。在本例中,我选择了test id 1、4和6。然后,用户将单击行中的“run”按钮并加载ajax.php、ajax2.php和ajax3.php。进度条(绿色)将显示脚本的进程以及状态文本。
问题是我找不到一种方法来对每行中的每个“test id”进行个性化设置。我首先在标记((button),(progress))中使用了'id'而不是'class',但它只适用于第一个选定的测试id。如果我使用'class',所有按钮都将具有相同的功能,所有加载条都将加载。
搜索.php
<?php
...
while($row = $result->fetch_assoc()){
$field1name = $row["test_id"];
$field2name = $row["path"];
$field3name = $row["video1_path"];
$field4name = $row["video2_path"];
$field5name = $row["video3_path"];
$field6name = $row["video4_path"];
echo "<tr>
<td> ".$field1name." </td>
<td> ".$field2name." </td>
<td> ".$field3name." </td>
<td> ".$field4name." </td>
<td> ".$field5name." </td>
<td> ".$field6name." </td>
<td><div>
<button id='btn'>Run</button>
</div></td>
<td><div><progress id='progBar' value='0' max='100'></progress></div></td>
<td><div><p id='progress-text' class='progress-text'></p></div></td>
<td><div id='result'>
<p></p>
</div></td>
</tr>";
}
}else {
echo '<span style="color:#ff0000;text-align:center;">No Test ID Selected!</span>';
}
}
// Close connection
mysqli_close($conn);
?>
</table>
</div>
<!--Uses jquery to run 3 scripts and displays it in a progress bar-->
<script>
$(document).ready(function(){
$("#btn").click(function(){
//Start of 1st script
$.ajax({
url: "ajax.php",
type:"POST",
success: function(data) {
//alert("File 1 Completed")
$("#progress-text").text("Executing file 1");
$('#progBar').val(25);
//Start of 2nd script
$.ajax({
url: "ajax2.php",
type:"POST",
success: function(data2) {
//alert("File 2 Completed")
$("#progress-text").text("Executing file 2");
$('#progBar').val(50);
//Start of 3rd script
$.ajax({
url: "ajax3.php",
type:"POST",
success: function(data2) {
//alert("File 2 Completed")
$("#progress-text").text("Complete");
$('#progBar').val(100);
//Try to edit the bottom part <a>
$("#result").load("pdf_report.php");
}
})
}
})
}
})
return false;
});
});
</script>
在这里,路径($field2name)作为输入参数发送到批处理文件
ajax.php文件
<?php include 'search.php' ?>
<?php
$var1 = $field2name;
// $var2 = "username"; //this is username
// $var3 = "password"; //this is username
// $var4 = "C:\myCSV_FolderPath";
$bat_file = "ecutestauto.bat " . escapeshellarg($var1) . " " . escapeshellarg($var2) . " " . escapeshellarg($var3) . " " . escapeshellarg($var4) . " ";
$output = null;
exec($bat_file, $output);
电子测试自动.bat
@echo off
set name=%1
START "" "%name%"
注意:ajax2.php和ajax3.php只是为了练习,它只是为了帮助模拟加载条。
问题:我想对每一行中的每个测试id进行个性化设置,并通过单击按钮将表行中受尊重的路径发送到bat文件。
暂无答案!
目前还没有任何答案,快来回答吧!