我目前正在尝试创建一个搜索菜单,并以表格形式显示结果。我设法只将搜索结果作为字符串,但无法使用它在表格中显示完整的行。 这是我的代码: - 创建表单:
<form action = "profile.php" method = "post">
<input type="text" name="search" placeholder = "Search">
<input type="submit" value = "SEARCH"><br>
</form>
这是获取搜索结果的php
if(isset($_POST['search']))
{
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM identity WHERE fullname LIKE '%$searchq%'") or die("Could not Find!");
$count = mysql_num_rows($query);
if($count == 0)
{
$output = 'There is no result';
}
else
{
while($row = mysql_fetch_array($query))
{
$fullname = $row['fullname'];
$output .= '<div> '.$fullname.' </div>';
$records = mysql_query("SELECT * FROM identitas_pengadu WHERE fullname='$output'");
}
}
}
这是我用来在数据库中显示结果的代码:
while($identity = mysql_fetch_assoc($records))
{
echo "<tr>";
echo "<td>".$identity['fullname']."</td>";
echo "<td>".$identity['nip']."</td>";
echo "<td>".$identity['email']."</td>";
echo "<td>".$identity['position']."</td>";
echo "<td>".$identity['status']."</td>";
echo "<td><a href=\"profiledetails.php?nip=".$identity['nip']."\">EDIT</a></td>";
echo "</tr>";
}
如果$ records的值不使用WHERE函数,它可以正常工作。请帮忙。 谢谢