简体   繁体   English

如何使用 Dynamic SQL 或 mySQL Prepared 语句从下拉列表中过滤搜索结果?

[英]How can I use either Dynamic SQL or mySQL Prepared statements to filter search results from a dropdown list?

I only have about 2 months worth of PHP under my belt, but I am having trouble trying to find an answer to a problem.我只有大约 2 个月的 PHP,但我在尝试找到问题的答案时遇到了麻烦。 I want to at least have four dropdown menus that will have options of selecting: car make, model, manufacturer, etc, and then take the selected option from each dropdown box and create a custom query to pull from a car database that I have created.我想要至少有四个下拉菜单,其中包含以下选项:汽车制造商、型号、制造商等,然后从每个下拉框中选择所选选项并创建一个自定义查询以从我创建的汽车数据库中提取. I believe the answer lies somewhere with Prepared Statements, but I am having trouble finding an answer.我相信答案就在准备好的陈述中,但我很难找到答案。 Any reference/help would be most appreciated.任何参考/帮助将不胜感激。

Can you please provide code what you have so far.你能提供你到目前为止的代码吗? I don't think this is related to Prepared Statements.我不认为这与准备好的报表有关。 If your dropdown's are not related in the way that second dropdown will be populated based on selection from first, then just do simple POST request, get data from dropdown's and make something like this如果您的下拉列表与根据第一个选择填充第二个下拉列表的方式无关,那么只需执行简单的 POST 请求,从下拉列表中获取数据并进行类似的操作

$first = $_POST['ddown1'];
$sedond = $_POST['ddown2'];
$third = $_POST['ddown3'];
$fourth = $_POST['ddown4'];
 $sql = "SELECT * FROM cars WHERE model = '$first' AND manufacturer = '$sedond' AND color = '$third'";

If you don't know how many data will be sent then just use concatenating assignment operator (.=)如果您不知道将发送多少数据,那么只需使用连接赋值运算符 (.=)

$sql .= "WHERE ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 PDO 与准备好的语句一起使用以更新 SQL? - How can I use PDO with Prepared Statements for update SQL? 如何在 CodeIgniter 中使用准备好的语句 - How can I Use Prepared Statements in CodeIgniter 如何从带有PHP预准备语句的SQL Server存储过程中返回多个结果? - How do I return multiple results from a SQL Server Stored Procedure with PHP prepared statements? 我现在可以用PDO使用真正准备好的MySQL语句吗? - Can I use real prepared statements for MySQL with PDO now? 如何从面向对象的Mysqli准备语句中分配结果 - How Can I Assign the Results from Object Oriented Mysqli Prepared Statements 如何使用准备好的语句增加mysql中的列? - How can I increment a column in mysql using prepared statements? 使用php动态变量php从SQL select和update语句的下拉列表中获取 - Use a dynamic variable of php getting from dropdown list in sql select and update statements 如何使用与PHP交易相结合的预准备语句? - How can I use prepared statements combined with Transactions with PHP? PHP,MySQL准备的语句-您可以通过调用data_seek(0)多次使用执行结果吗? - PHP, MySQL prepared statements - can you use results of execute more than once by calling data_seek(0)? 显示准备好的语句的结果 - Displaying Results from Prepared Statements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM