如何在php中保留下拉框的值 [英] how do retain value of dropdown box in php

查看:56
本文介绍了如何在php中保留下拉框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尝试使其尽可能简单.我知道如何在下拉菜单中选择默认值.我的问题是如何使下拉菜单中的最后一个选项在下一次默认为交互".因此,我无法对默认值进行硬编码.

I will try to make it simple as possible. I know how to select a default value in dropdown. My problem is how to make the last option in the dropdown as default "interactively" for next time. so that means that I cannot hardcode the default value.

让我们说我想将两个数字相乘.我有两个下拉框,其中包含1到10的数字;第一次会说1和1,因为如果未提及默认值,则默认值为第1个位置的数字.假设有人在第一个选择2,第二个选择6.用户点击计算后,页面将刷新,将显示答案12.我仍然希望2和6 stil在那里,而不是回到1和1

Lets say I want to multiply 2 numbers. I have two drop down boxes and contain number 1 to 10; at the very first time it will say 1 and 1 since if no default is mentioned, then the default is the number at 1st position. Lets say if somebody picks 2 in the 1st and 6 in the second. Once the user hits calculate, the page will refresh, the answer 12 will be displayed. I still want 2 and 6 stil to be there, and NOT go back to 1 and 1

请注意,如果我将操作设置为"answer.php",并在新页面上显示答案,并有一个返回按钮可返回到初始页面.没有问题.但我不想要那样我想留在同一页上.

Please note that if I have action set to "answer.php", and display the answer on a new page and have a back button to come back to initial page. There is no problem. but I don't want that. I want to stay on the same page.

我没有使用mysql.全部都有一个简单的for循环,我会动态加载值1到10

I am not using mysql. All have is a simple for loop and I dynamically load values 1 to 10

我认为我需要选择的东西= ??????请填写空白,我将其放在for循环中的位置

I believe I need something like selected = ?????? please fill the blank and where would I put this in the for loop

我在Google上花费了整整一整天的时间,但是对我想要的没有运气

I have spent whole day on this on google but no luck to what I want

谢谢

授予

推荐答案

执行此操作的方法有很多,区别在于您希望存储的深度.在不浪费太多时间的情况下,以下是存储选项的快速列表:

There are many ways to do this, the differences come down to how 'deep' you want the storage to be. Without wasting too much time here is a quick list of storage options:

  • POST vars(这是最适合您的情况的解决方案)
  • 饼干
  • 会话
  • 数据库
  • 服务器文件系统
  • 等等等

基本上,最简单的技术是获取传递的数据并重新显示,因此对于您的表单,您有2个输入, leftval & rightval ,用户点击表单上的Submit,然后将它们相乘以显示结果.

Basically the simplest technique is to take the data that is passed and redisplay it, so for your form you have 2 inputs, leftval & rightval, the user hits submit on the form and you multiply them to show the result.

构建页面以显示结果时,请使用$ _POST ['leftval']&$ _POST ['rigtval']将其填充到新页面上.确保对这些值进行清理,并在退出过程中将其转义!

When you build the page to show the result use the $_POST['leftval'] & $_POST['rigtval'] to populate them on the new page. Make sure to sanitize the values and escape them on the way out!

这篇关于如何在php中保留下拉框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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