简体   繁体   English

让PHP实时选择一个选项?

[英]Letting PHP select an option in real time?

I'm building a CMS that have 2 database tables, subjects & pages ... I have two drop down lists..And i want to let the user to insert values in it ... 我正在建立一个具有2个数据库表,主题和页面的CMS ...我有两个下拉列表..我想让用户在其中插入值...

The first drop down list is to select which table to insert in. The second drop down list is to select the position of the inserted item in that selected table. 第一个下拉列表用于选择要插入哪个表。第二个下拉列表用于选择插入的项目在所选表中的位置。

So I want the user to select the table first, then -using PHP- change the second drop down list to contain the available position in that table. 因此,我希望用户首先选择表,然后-使用PHP-更改第二个下拉列表以包含该表中的可用位置。 Note that all the previous stuff is in the same web page without pressing any button or something. 请注意,所有先前的内容都位于同一网页中,而无需按任何按钮或其他按钮。

So all I want, a method to make PHP check the selected option in the first drop down list, and change the options in the second according to the first drop down list, all that in the same page without pressing any button.. 因此,我想要的是一种使PHP在第一个下拉列表中检查所选选项,并根据第一个下拉列表更改第二个选项的方法,所有这些操作均在同一页面中,而无需按任何按钮。

Is that possible in PHP ? 这在PHP中可行吗?

You can use PHP in the background, but as selecting an option happens on the client side you'll have to use a combination of JavaScript/Ajax. 您可以在后台使用PHP,但是在客户端选择选项时,您将不得不使用JavaScript / Ajax的组合。

Have a look at YUI Autocomplete or other Ajax autocomplete frameworks. 看一下YUI自动完成或其他Ajax自动完成框架。

The short answer to your question is no. 您问题的简短答案是“否”。 PHP is server side, ie it can't be changed by user interactions without refreshing the page as it has finished executing before the HTML reaches the browser. PHP是服务器端的,即,在HTML到达浏览器之前,页面已经完成执行,因此如果不刷新页面就无法通过用户交互进行更改。

To do this you will need to use javascript and ajax. 为此,您将需要使用javascript和ajax。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM