以下代码来自我的朋友。我想根据这些代码进行搜索。从此代码中,它将显示要删除的所有用户。我想要的是我想把搜索框和搜索按钮。所以当我插入用户ID并按下搜索时,它会显示我想要的用户。我应该把这个搜索文本,按钮和PHP放在哪里?如果代码,我想把它放在其他地方。帮我。我是新的:(
else if($_SESSION['jawatan'] == 'ADMIN') { ?>
<li> <a href="view.php">VIEW PROFILE</a> </li>
<li> <a href="request.php">VIEW REQUEST</a> </li>
<li><a href="logout.php">LOG OUT</a></li>
<li><img src="msc.jpg" width = "240" height ="80"></li>
<form method="get">
<input type="text" name="userid" placeholder="search" />
<inpu type="submit" value="Search" />
</form>
<h3>View User</h3>
<table border='1'>
<tr>
<td><b>#</b></td>
<td><b>Nama</b></td>
<td><b>Email</b></td>
<td><b>Division</b></td>
<td><b>Department</b></td>
<td><b>Delete</b></td>
</tr>
<?php
$i = 1;
$whr="";
if(isset($_GET['userid'])){
$whr.= " and mem_id='".$_GET['userid']."'"; // which field you want. If you want to do search name use LIKE instead =(equal to)
}
$result = mysql_query("SELECT * FROM members WHERE mem_role='USER' ".$whr);
if(mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td>
<?php echo $i; ?>
</td>
<td>
<?php echo $row['mem_name']; ?>
</td>
<td>
<?php echo $row['mem_email']; ?>
</td>
<td>
<?php echo $row['mem_division']; ?>
</td>
<td>
<?php echo $row['mem_department']; ?>
</td>
<td><a href="delete.php?var1=admin&var2=<?php echo $row['mem_id'];?>">Delete</a></td>
</tr>
<?php
$i++;
}
} else {
echo '<tr><td>No results found</td></tr>';
}
?>
</table>
<?php
}
答案 0 :(得分:0)
我可以告诉你步骤:
创建搜索文本字段和搜索按钮(如果您只想使用php,请在表单中包装)
点击按钮(即提交),从搜索文本框中获取该值并根据该值运行查询
显示结果时,使用foreach
使用该结果填充表格数据。
答案 1 :(得分:0)
HTML
<form method="get">
<input type="text" name="userid" placeholder="search" />
<inpu type="submit" value="Search" />
</form>
PHP
$whr="";
if(isset($_GET['userid'])){
$whr.= " and mem_id='".$_GET['userid']."'"; // which field you want. If you want to do search name use LIKE instead =(equal to)
}
MYSQL
$result = $result=mysql_query("SELECT * FROM members WHERE mem_role='USER' ".$whr);// add whr variable here