【发布时间】:2017-03-26 14:40:57
【问题描述】:
我在文件搜索方面遇到问题。我有 2 个文本表单,我想在其中输入值以在文件中进行搜索。但不知何故,如果我以其中一种形式编写输入,它也会显示在另一行中(我不想要这个)。此外,我的搜索仅适用于搜索选项之一(其中变量为 $search)。
<?php
function f_display(){
global $file;
?>
<form action=<?php echo $_SERVER['PHP_SELF'] ;?>>
<input type=text name=search value="<?php echo $_GET['search'] ; ?>">
<input type=submit value=Message_Search>
</form>
<form action=<?php echo $_SERVER['PHP_SELF'] ;?>>
<input type=text name=search value="<?php echo $_GET['search'] ; ?>">
<input type=submit value=Name_Search>
</form>
<?php
$f = fopen($file,"r");
$x = 'bgcolor="#AAAAAA"';
$y = 'bgcolor="#FFFFFF"';
$search = $_GET['search'];
$searchname = $_GET['search'];
echo "<table width=50% border=1><tr><th> </th><th>vardas</th><th>nikas</th><th>pranesimas</th></tr>";
if (filesize($file)>0){
while (!feof ($f)) {
$string = fgets ($f,1000);
$part = explode ( "|" , $string );
if ( @stristr($part[2] , $search) == false and $search) continue ;
echo "<tr $tr_spec ><td><a href = \"index.php?aaa=2&id=$i\"></a></td><td>" . $part[0] . "</td><td>". $part[1]." </td><td>". $part[2] ."</td></tr>";
if ( @stristr($part[0] , $searchname) == false and $searchname) continue ;
echo "<tr $tr_spec ><td><a href = \"index.php?aaa=2&id=$i\"></a></td><td>" . $part[0] . "</td><td>". $part[1]." </td><td>". $part[2] ."</td></tr>";
} // while
} // if
fclose ($f);
echo "</table>";
?>
文件看起来像:
John|J0N|Hello
Peter|P3tE|Wow
Paul|PO|Nice
也许你可以给我一些东西或告诉我我做错了什么?
【问题讨论】: