douti9253 2013-07-09 10:28
浏览 22
已采纳

php输出结果[关闭]

I am getting confused as I read various posts about the typical task I am trying to perform, no doubt countless others have done it before. So at this point in 2013 what is the best practice solution to achieve the following:

  • I have an html page which asks the user for a number of values, x1, x2, .....xn.
  • There may be 10 to 20 such inputs. As such I don't want them to be lost or to have to be re-inputted again for whatever reason.
  • perform calculations based on user inputs then output the results (eg. y1, y2, y3..y5).
  • As suggested by some of the posts here, I tried "echo" (for PHP), that works fine. However, it shows the results in a new page so the user input is no longer visible.
  • I want the user to see both - their input and the resultant. That way they can print if they want to and see all info on one page.
  • I prefer to use "basic" technologies, ie. technologies that most users can use, that they don't have to click OK on some warning, change some setting on their browser, accept some thing or other etc..

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • doudaifu6083 2013-07-09 10:32
    关注
    1. Create inputs with html.
    2. Choose between reloading page or AJAX
    3. If you choose reloading then use

    code:

      <form action="nextfile.php" method="POST">
       <input type="text" value="" name="y1" />
       <input type="text" value="" name="y2" />
       <input type="submit" value="calc me" name="submit" />
      </form> 
    

    Then in nextfile.php you need get values with $_POST and if you want them to be saved use $_SESSION

    For example

    <?php 
    session_start();
    if(isset($_POST['y1']) && isset($_POST['y2']))
    {
        $_SESSION['res'] = (int)$_POST['y1'] * (int)$_POST['y2'];
    }
    

    The code above will perform calculation on two inputs with name y1 and y2 and save them in session.

    If you want AJAX then you need to visit this page and see examples

    You should think of JavaScript solution because it will fit your needs and no server code is needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并