[英]Adding an “all” option to my HTML select tag
So I'm on my way to completing my website. 因此,我正在完善自己的网站。 However I was wondering, how can I structure my SQL statement so when I click the submit button with an option having "all" I get all the results in that field with the addition of the other criteria.
但是我想知道,如何构造我的SQL语句,所以当我单击带有“全部”选项的“提交”按钮时,我将获得该字段中所有其他结果的附加结果。 If you know any good tutorials could you please recommend one.
如果您知道任何优秀的教程,可以推荐一个。
<select name="make" id ="make" size="0">
<option selected ="all">All</option>
<option value="bmw">BMW</option>
<option value="honda">Honda</option>
<option value ="nissan">Nissan</option>
<option value="toyota">Toyota</option>
</select>
$sql = sprintf("SELECT * FROM `chjadb_vehicles` WHERE `v_make` LIKE '$make');
Here's one approach that only requires changing the SQL: 这是只需要更改SQL的一种方法:
SELECT *
FROM chjadb_vehicles
WHERE (v_make = '$make' OR '$make' = 'all')
The parentheses are not strictly necessary here but I added them anyway in case you later decide to add another AND ...
condition. 此处的括号不是严格必需的,但是无论如何我还是添加了它们,以防您稍后决定添加另一个
AND ...
条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.