我需要一個PHP腳本,將使用窗體的複選框的值作爲MySQL查詢檢索數據。我想我需要在查詢中使用WHERE和OR運算符。檢索數據與表格使用WHERE多個複選框
我的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子句將在所有被添加,它會默認爲檢索的所有記錄。
使用單選按鈕。不是複選框。 – 2012-04-14 15:04:24
@Truth也許多選都是有效的。 – 2012-04-14 15:04:48
@joeframbach:是的,我想要一個1層和2層的房子,有兩個和三個浴室。 – 2012-04-14 15:05:56