[英]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.