我需要搜索一个文本文件,该文件的值由逗号(“,”)分隔。通过文本框搜索值时,我已经能够成功搜索文件并显示结果,但是使用单选按钮扩大搜索范围并不成功。
我尝试遵循相同的语法,并添加了“ ||”有关单选按钮的值,请在下面的代码中显示:
$titleSearch = explode(",", $_REQUEST["title"]);
$positionSearch = explode(",", $_REQUEST["position"]);
$lines = file("$dir/jobs.txt");
foreach($lines as $line){
if(stripos($line, $titleSearch[0]) !== false || stripos($line, $positionSearch[0]) !== false){
echo "<tr>";
echo "<td>";
$data = explode(',', trim($line));
echo $data[0];
echo "</td>";
echo "<td>";
echo $data[1];
echo "</td>";
//code goes on for a bit...
在搜索表单中仅搜索“ Sys”将提供所需的结果:
ID Title Description Closing Date Position Contract Application type Location
P0001 Sys Admin This is a test description for the assignment. 09/04/19 Full Time Fixed Term Post and Mail VIC
P0002 Sys Admin This is a test description for the assignment. 09/04/19 Part Time Fixed Term Post QLD
但是,仅单击“全职”或“兼职”单选按钮之一将在文本文件中显示所有结果。我的代码中还有其他内容,如果未选择任何选项,则显示所有结果。
表单代码:
<p>
Position:
<input type="radio" name="position" value="Full Time">Full Time <input
type="radio" name="position" value="Part Time">Part Time<br>
</p>
我还需要通过复选框和一行下面的下拉列表进行搜索。
谢谢。