dragon_9000 2018-01-02 11:32
浏览 17
已采纳

如何在另一个页面中设置和调用php中的指令

In calculate.php I have this code:

//recovery the variables from an html form
$FirstNumber=$_POST['FirstNumber'];
$SecondNumber=$_POST['SecondNumber'];
$Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.
//Now I have to call specific instructions in instructions.php (Which is the one for operations) sending to it my variables
//Now I have to recovery $result from instructions.php
echo "Result: $result";

Assume that in instructions.php I have this:

The page need to understand what instruction it have to do, in this case the ones from Operations sector

//-----Operations-------------------------------------------------------------------------
//recovery variables from calculate.php
//Tottaly doesen't know how
switch ($Operation){
case "+":
$result=$FirstNumber+$SecondNumber;
//Now I send the result in calculate.php
break;
//repeat for all the possible cases
}
//------Strings---------------------------------------------------------------------------
$control=$String;
if ($checked){
$control=$String."_Controlled";
//I have to return $control
}else {
$checked=true;
 $control=$String."_Controlled";
//return $control
}
//------Other instructions for other requests---------------------------------------------

So, How can I "define" and call a series of instruction from another php page?

Please don't answer me with the "meta refresh" method, it's not what I'm looking for and what I asked.

  • 写回答

2条回答 默认 最新

  • duanhan5388 2018-01-02 11:47
    关注

    You're having option to include the page with all the function into current page using require_once or require method

    now you can use the page where you are getting the variables in post method and include another page on the same page at the starting point for example,

    if you are getting variables on calculate.php in post method then you can use require at the top of calculate.php

    <?php
        require('path/to/operation.php');
    
        //recovery the variables from an html form
        $FirstNumber=$_POST['FirstNumber'];
        $SecondNumber=$_POST['SecondNumber'];
        $Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.
    
        echo "Result: ". calculate($Operation, $FirstNumber, $SecondNumber);
    ?>
    
    
    
    //In your Operation.php it should be like function, and you can call that function using calculate.php to get the result.
    
    function calculate($Operation, $FirstNumber, $SecondNumber)
        switch ($Operation){
            case "+":
                $result=$FirstNumber+$SecondNumber;
                return $result;
            break;
        }
        $control=$String;
        if ($checked){
            $control=$String."_Controlled";
            //I have to return $control
        }else {
            $checked=true;
            $control=$String."_Controlled";
            //return $control
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100