PHP/MySQL - 如何组合来自不同表单的变量来构建查询?

发布于 2024-11-02 09:13:34 字数 336 浏览 6 评论 0原文

请查看此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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻泪 2024-11-09 09:13:34

如果有人读到这个问题并想知道我是如何解决它的,我使用隐藏输入和一些 JQuery 将值从简单搜索表单复制到隐藏输入,如下所示:

<input type="hidden" name="hiddenfilename" id="hiddenfilename"/>
<input type="hidden" name="hiddenfilesize_min" id="hiddenfilesize_min"/>
<input type="hidden" name="hiddenfilesize_max" id="hiddenfilesize_max"/>
//etc

<script type="text/javascript">
$("#filename").change(copyFilename);
$("#filesize_min").change(copyFileSizeMin);
$("#filesize_max").change(copyFileSizeMax);

function copyFilename()
{
   var valueToCopy=$("#filename").val();
   $("#hiddenfilename").val(valueToCopy);
}

function copyFileSizeMin()
{
   var valueToCopy=$("#filesize_min").val();
   $("#hiddenfilesize_min").val(valueToCopy);
}

function copyFileSizeMax()
{
   var valueToCopy=$("#filesize_max").val();
   $("#hiddenfilesize_max").val(valueToCopy);
}
</script>

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:

<input type="hidden" name="hiddenfilename" id="hiddenfilename"/>
<input type="hidden" name="hiddenfilesize_min" id="hiddenfilesize_min"/>
<input type="hidden" name="hiddenfilesize_max" id="hiddenfilesize_max"/>
//etc

<script type="text/javascript">
$("#filename").change(copyFilename);
$("#filesize_min").change(copyFileSizeMin);
$("#filesize_max").change(copyFileSizeMax);

function copyFilename()
{
   var valueToCopy=$("#filename").val();
   $("#hiddenfilename").val(valueToCopy);
}

function copyFileSizeMin()
{
   var valueToCopy=$("#filesize_min").val();
   $("#hiddenfilesize_min").val(valueToCopy);
}

function copyFileSizeMax()
{
   var valueToCopy=$("#filesize_max").val();
   $("#hiddenfilesize_max").val(valueToCopy);
}
</script>
寂寞陪衬 2024-11-09 09:13:34

我不会读 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文