在我下面的代码中,我一直在从数据库中查询姓名和电子邮件,在本例中,如果姓名或电子邮件为空,它将获取所有数据。
如何避免这种情况?请帮忙
mysql查询:
$searchdata = mysqli_query($this->dbh, "SELECT insertdata.name, insertdata.email, state.StateName, district.DistrictName
FROM insertdata
INNER JOIN state ON insertdata.state = state.StCode
INNER JOIN district ON insertdata.district = district.DistCode
WHERE name LIKE '%$namesearch%' OR email LIKE '%$emailsearch%'");
我的密码,
<?php
include_once("function.php");
$searchdata=new DB_con();
if(isset($_POST['submit']))
{
$namesearch=$_POST['namesearch'];
$emailsearch=$_POST['emailsearch'];
}
$search=$searchdata->searchdata($namesearch,$emailsearch);
foreach($search as $search)
{
?>
<tr>
<td><?php echo ($search['name']);?></td>
<td><?php echo ($search['email']);?></td>
<td><?php echo ($search['StateName']);?></td>
<td><?php echo ($search['DistrictName']);?></td>
</tr>
<?php
}
?>
2条答案
按热度按时间yx2lnoni1#
在不同的条件下写不同的语句怎么样
ca1c2owp2#
只要加上这个条件,检查它是否是空的