我需要一个 php 脚本,它将使用表单复选框的值作为 MySQL 查询来检索数据。我想我需要在查询中使用 WHERE 和 OR 运算符。
我的 PHP 和 MySql 级别是初学者。
<form id="form1" name="form1" method="post" action="">
<p>
<h3>story</h3>
<label><input type="checkbox" name="story" value="1" id="story_1" />one story</label>
<label><input type="checkbox" name="story" value="2" id="story_2" />two story</label>
</p>
<p>
<h3>bedrooms</h3>
<label><input type="checkbox" name="bedroom" value="2" id="bed_2" />two beds</label>
<label><input type="checkbox" name="bedroom" value="3" id="bed_3" />three beds</label>
<label><input type="checkbox" name="bedroom" value="4" id="bed_4" />four beds</label>
</p>
<p>
<h3>baths</h3>
<label><input type="checkbox" name="bath" value="1" id="bath_1" />one bath</label>
<label><input type="checkbox" name="bath" value="2" id="bath_2" />two baths</label>
<label><input type="checkbox" name="bath" value="3" id="bath_3" />three baths</label>
</p>
<input type="submit" name="search" value="search" />
</form>
到目前为止我的查询
SELECT * FROM homes WHERE story='1' OR story='2' OR bed='3' OR baths='3'
因此,如果未选中任何复选框,则根本不会添加 WHERE 子句,并且默认检索所有记录。