PHP:在服务之前重新解析整个页面?
在页面结束时,如果发生了某些情况,需要将其清除,然后在向客户端提供服务之前需要重新解析整个页面。 我本来打算回显 JavaScript 来刷新页面,但这会让他们加载页面,然后重新加载它...我想知道是否有一种方法可以告诉 php 引擎返回到开头并重新加载- 解析整个页面?
谢谢!
我会尝试更清楚地解释这个问题,但它很复杂,而且我的沟通能力很差。 在列出产品的页面上,我为用户提供了选择字段以缩小结果范围的选项。 系统会记住这一点,因此他们不必继续选择它们。 如果他们缩小金属颜色等类别,然后转到与金属颜色无关的类别(如水晶雕像),则不会显示任何结果,因为没有一个与所选的金属颜色匹配。 生成从数据库中提取产品的查询非常复杂,因为不同的类别对于查找正确的产品有不同的要求。 因此,一旦生成查询,我想针对 mysql_num_rows() 对其进行测试,如果没有结果,则清除用户的选择并重新开始。
At the end of a page, if something occurs, it needs to be cleared, then the entire page needs to be re-parsed before serving to the client. I was going to echo out a javascript to refresh the page, but that will make them load the page and then reload it...I was wondering if there was a way to just tell the php engine to go back to the beginning and re-parse the entire page?
Thanks!
I will try to explain the problem more clearly but it is complicated and I am a terrible communicator. I on the page that lists products I am giving users the option to select fields to narrow the results. The system remembers this so they don't have to keep selected them. If they narrow a category like metal color and then go to a category that metal color is irrelevant like crystal figurines it will not show any results because none will match the metal color chosen. To generate the query to pull the products from the data-base is very complicated because different categories have different requirements to find the correct products. so once the query is generated I want to test it against mysql_num_rows() and if there is no results clear out the users choices and start over.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你有点含糊,但如果你只是谈论重新解析输出,你可以使用 output 来做到这一点缓冲。
You're being a little vague, but if you're merely talking about reparsing the output, you could do that using output buffering.
我不完全清楚问题是什么,但是您不能在创建 HTML 之前决定要显示的内容,然后第一次发送正确的内容吗?
I'm not entirely clear what the issue is, but couldn't you decide what is to be shown before creating the HTML, and then send the right thing the first time?
在这种情况下,只需将查询放入返回结果的函数中,检查行数,如果为零,则清除过滤器并再次调用该函数。
In that case, just put the query inside a function that returns the result, check the row count, and if it's zero clear the filters and call that function a second time.
输出缓冲(ob_start 和 ob_clean),与将手头的功能分离到一个单独的文件中以及 eval() 相结合,应该可以解决问题。
哦,最近的 PHP 版本实际上有一个 goto 语句...尽管我总是否认提及任何有关它的事情。 :-)
Output buffering (ob_start and ob_clean), combined with separating the functionality at hand into a separate file and eval()'ing that should do the trick.
Oh, and recent PHP versions actually have a goto statement... although I'll always deny mentioning anything about it. :-)
我觉得你的想法有点偏离了。
重新解析页面应该做的是再次将用户重定向到该页面,
但是如果您实际上想重新解析文件而不创建新页面,您也可以再次包含该文件:
include thepagefile.php
但是您可能会得到相同的结果。 如果您想实际解析页面的输出,您可以执行以下操作:
但这实际上没有意义,但我希望它有所帮助。
我实际上想知道您想要解决的真正问题是什么。
I think you're going about it a little bit off.
What you should do to reparse the page is to redirect the user to the page again, using
however if you actually would like to reparse the file without creating a new page, you could also just include the file again:
include thepagefile.php
But you'd probably get the same result. If you want to actually parse the output of the page you'd do something like:
but that actually makes no sense, but I hope it helps.
I'd actually like to know what the real problem you're trying to solve really is.
我想你正在寻找这样的东西:
I think your looking for something like this: