可能重复:
Display in the table if search matches in php显示项目,如果搜索匹配
看到我在PHP从dat文件的搜索,这是我到目前为止的代码:
<?php
if (isset($_POST["name"]))
{
$file = 'order.dat';
$searchfor = $_POST["name"];
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^$pattern.*$/m";
if(preg_match_all($pattern, $contents, $matches))
{
$result = explode('|', $matches[0]);
}
else{
echo "No matches found";
}
}
?>
<h3>Search Order Details</h3>
<form method="post" action="search.php" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
order.dat文件包含: -
175|RC456456456|54156456177|177$
176|RC456456177|54156456177|177$
177|RC456456177|54156456465|129$
178|RC456456456|54156456177|177$
现在现在如果搜索发现,于是说找到匹配...就像如果我进入177的它给 Found matches: 177|RC456456177|54156456465|129$
现在如果我输入002,然后它说未找到匹配
My Question is
我想在这个表格中显示,如果搜索匹配: -
<table>
<tr>
<th>Order number </th>
<th>Tranasaction id</th>
<th>Date </th>
<th>Total Price</th>
</tr>
<td><?=$result[0]?></td>
<td><?=$result[1]?></td>
<td><?=$result[2]?></td>
<td><?=$result[3]?></td>
</table>
问题是? –
@Baszz :)我想在表中显示,如果搜索匹配 – John