PHP日期下拉输入到格式化输出 [英] PHP Date Dropdown Input to Formatted Output

查看:177
本文介绍了PHP日期下拉输入到格式化输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提供一个HTML页面,为MonthName,Day和Year提供3个下拉列表。当用户点击提交时,用户选择的日期现在以这种方式格式化:月#/日/年以及消息您已选择(日期)。



下拉列表必须使用PHP中的循环完成。我不确定如何让选定的May以5的形式出现。



我没有任何代码可以使用,因为我'我甚至不知道从哪里开始。我不确定如何让HTML元素与PHP交互。



任何想法都有帮助。我很难搞清楚,更不用说开始了。



如何以格式化的方式输出PHP下拉列表?

I need to come up with an HTML page that provides 3 dropdowns for MonthName, Day, and Year. When user hits Submit, the date that was selected by the user is now formatted in this way: Month#/Day/Year along with the message "You have selected (date)."

The dropdown list has to be done using loops in PHP. I'm not sure how to get a selected "May" to come out as "5."

I don't have any code to work from because I'm not even sure where to begin. I'm not sure how to get HTML elements to interact with PHP.

Any ideas are helpful. I'm having a hard time figuring it out, let alone getting started.

How can I get the PHP dropdown list to be output in the formatted way?

推荐答案

嗨朋友,



我理解初学者面临的问题。但我想问一个问题,你有什么逻辑准备在你的脑海里。逻辑是代码的执行方式,并不意味着任何语言边界。这可以是一个简单的流程图或简单的英语点的方法。以下是后者的一个例子。



1.首先,页面将显示三个选择框 - >日月年。这意味着我必须使用一些html来显示它。



2.当用户选择值并点击提交按钮时(暗示,我有一个表单元素)在HTML)中,数据将转到某些PHP脚本。

我的PHP脚本与生成HTML表单的页面相同(例如,index.php)。



3.这意味着我应该有一个方法来检测用户是否刚刚加载了一个页面,而是将表单数据发送给它。

这也意味着使用了分支。即if-else块被使用。

喜欢,如果提交== True,那么

//做某事来处理表单数据并显示结果

Else //显示表格让用户输入数据



4.现在,如果用户使用表格向我提交了数据,我也必须获取该数据并将其存储在临时变量中。

这取决于提交表单的方法。对于初学者,我想说,GET和POST有两种方法,通过它们可以提交表单数据
。当您看到在http://example.com/process.php?data=somedata&data2=something

等网址中提交的表单数据时,这是GET方法的示例。在POST方法中,数据以不同的方式发布,你将看不到任何查询字符串

url。



5。我现在应该使用GET方法,所以我将在PHP中使用一个方法来获取这些数据。这是
Hi Friend,

I understand the problems that beginners face. But I want to ask one, thing, do you have a logic ready in your mind. Logic is how the code is going to execute which doesn't imply any language boundary. This can be a simple flowchart or simple english like points approach. Here's an example of the latter.

1. First, the page will display three select boxes -> Day, Month, Year. This implies that I have to use some html to display this.

2. When a user will select the values and hit Submit button (implies, I have a form element in HTML), the data is going to some PHP script.
My PHP script is the same page that generated the HTML form (say, index.php).

3. This implies that I should have a method to detect if a user has not just loaded a page but rather has sent the form data to it.
This also implies that a branching is used. i.e. if-else block is used.
Like, If submitted == True, Then
// Do Something to process the form data and display the result
Else // Display the form to let the user input the data

4. Now, if user had submitted the data to me using the form, I have to get that data too and store it in a temporary variable also.
This depends on the method via which the form is submitted. For starters, I would say, there are two methods GET and POST, via which
a form data is submitted. When you see form data submitted inside a url like http://example.com/process.php?data=somedata&data2=something
This is the example of GET method. While in POST method, the data is posted in different way and you will not see any query string in
the url.

5. I should be using GET method at the moment, so I will have a method in PHP to get this data. this is


_GET ['data']。无论是什么内部

单引号是表单元素的名称属性,如Textboxes,Selectboxes等。你得到的是发布给你的价值。



6.现在我们已经在页面中存储了所有变量,我们将处理细节...这是一个例子(在PHP中高度评论)



_GET['data']. Whatever is inside
the single quote is what the name attribute of the form elements like Textboxes, Selectboxes etc. What you get is the value posted to you.

6. Now that we have stored all the variables in the page, we will be processing the details ... Here's an example (Highly Commented in PHP)

    // First thing to check is if user has submitted any data to this page via the form
    // We will use if-else condition here
    // The isset function checks if the variable of the given name exists or not. The


_GET ['submit']是变量
// 当您通过GET提交任何表单数据时,PHP的
_GET['submit'] is the variable // When you submit any form data via GET, the PHP's


这篇关于PHP日期下拉输入到格式化输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆