PHP/MySQL - 如何组合来自不同表单的变量来构建查询?
请查看此pastebin中的代码: http://pastebin.com/5gKwb7gi
这是相当多的代码,但是我想在座各位高手都会明白的!
基本上我自己感到困惑的是,我有一个搜索表单,然后创建了一个动态的高级搜索表单。
我刚刚完成,现在我尝试在高级搜索查询中包含简单的搜索条件(如果已填写),但显然这些变量从未设置,因为简单的搜索表单从未提交:S
有人有任何提示吗、关于做什么的提示或想法?不确定我是否想合并这些表格,所以我希望得到一些建议和意见。
谢谢。
Please see the code in this pastebin: http://pastebin.com/5gKwb7gi
It is quite a lot of code but I think all you gurus on here will understand it!
Basically what I have just confused myself is, I had a search form, and I then created an advanced search form which is dynamic.
I just got it finished and now I am attempting to include the simple search criteria (if it is filled out) in the advanced search query but obviously these variables are never set because the simple search form is never submitted :S
Does anyone have any hints, tips or ideas on what to do? Not sure if I want to combine the forms or not so I would appreciate some advice and opinions.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人读到这个问题并想知道我是如何解决它的,我使用隐藏输入和一些 JQuery 将值从简单搜索表单复制到隐藏输入,如下所示:
If anyone reads this question and would like to know how I solved it, I used hidden inputs and some JQuery to copy the values from the simple search form to the hidden inputs like so:
我不会读 600 行代码来帮助你。将示例缩小到可以用一些单词来表达并且少于 50 行。这总是可能的!无论如何,我从我在这里读到的内容中回答,没有代码。
如果您想获取多页表单的数据,您有多种选择。您可以评估表单服务器端的每个页面,然后将它们放回您想要在第二步中放置它们的位置(对变量使用隐藏的导入标签,不应呈现这些标签)。另一种选择是将这些值放入 cookie 中,并在需要时从那里获取。您还可以根据用户输入使用 Javascript 更改表单的结构,然后在完成后发送整个内容(可能通过 AJAX)。第一个是最基本但通常也是最优雅的。出于学习目的,我建议这样做。 cookie 和 AJAX 的结合应该是最高级别也是最常用的一种,但也是最复杂的一种,因为你需要学习你的服务器和你的 php 代码如何处理 cookie,以及如何正确应用 Javascript。
I will not read 600 lines of code to help you. Make the example smaller that you can express it with some words and less then 50 lines. That is always possible! Anyway, I answer from what I read here without the code.
If you want to get Data for a multipage form you have several options. You can evaluate each page of your form server side, and then just put them back where you want to have them in the second step (use hidden import tags for variables, which should not be rendered). Another choice is to put the values into a cookie and take it from there when you need it. Also you can change the structure of your form with Javascript according to the user inputs and then just send the whole thing, when he is finished (maybe per AJAX). The most basic but often also most elegant one is the first one. For learning purposes I advice that one. Combining cookies and AJAX should be the highest level and the one used most often, but also the most complicated one, because you need to learn how your server and your php code handles cookies and also how to apply Javascript correctly.