【问题标题】:Update a PHP variable on the fly with ajax based on user input根据用户输入使用 ajax 即时更新 PHP 变量
【发布时间】:2013-08-01 15:21:41
【问题描述】:

我快疯了,因为我想不通.. 我正在创建一个代码,告诉我将打印多少个面板。

PHP 代码是这样的:

<?php
$base = 400; //the width
$altezza = 300; //the height (no need for calculation)
$larg_fasce = 60; //the size of each piece (always 60cm)

$num_fasce = floor($base/$larg_fasce); //calc the numbers of piece needed to cover the $base
$dim_fasce = floor($base/$num_fasce); //calc the size of each piece

$resto = $base-($num_fasce*$larg_fasce); //calc the rest to cover the $base



/////////////
echo "Base: ".$base."<br>";
echo "Altezza: ".$altezza."<br>";
echo "Largh Fasce: ".$larg_fasce."<br><br>";

echo "Verranno fornite ".$num_fasce." fasce da ".$larg_fasce." cm - tot (".$num_fasce*$larg_fasce."cm)<br>";
if($resto != 0){
echo "Verra fornita 1 fascia da ".$resto." cm";
}

?>

此代码完美运行(当我手动调整 $base 大小时)。 我需要这个变量“$base”取自输入字段并实时更新,我该怎么做?

【问题讨论】:

    标签: ajax split size real-time-updates


    【解决方案1】:

    设置 $base = $_GET['base'],你的网址是这样的:test.php?base=400 它会很好用。

    另一种方法是构建一个表单,它有一个让你输入$base,无论是通过post还是通过get,然后你就可以使用$base。

    希望对你有所帮助~~

    <?php
    $base = $_GET['base']; //the width
    $altezza = 300; //the height (no need for calculation)
    $larg_fasce = 60; //the size of each piece (always 60cm)
    
    $num_fasce = floor($base/$larg_fasce); //calc the numbers of piece needed to cover the $base
    $dim_fasce = floor($base/$num_fasce); //calc the size of each piece
    
    $resto = $base-($num_fasce*$larg_fasce); //calc the rest to cover the $base
    
    
    
    /////////////
    echo "Base: ".$base."<br>";
    echo "Altezza: ".$altezza."<br>";
    echo "Largh Fasce: ".$larg_fasce."<br><br>";
    
    echo "Verranno fornite ".$num_fasce." fasce da ".$larg_fasce." cm - tot (".$num_fasce*$larg_fasce."cm)<br>";
    if($resto != 0){
    echo "Verra fornita 1 fascia da ".$resto." cm";
    }
    
    ?>
    

    【讨论】:

    • 谢谢,但是我需要一个自动更新功能,因为这是一个提交订单的表单,所以我需要实时显示细分.. =(
    • 你想用ajax结束吗?@vonatar
    猜你喜欢
    • 2016-01-28
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 2021-04-08
    • 2015-08-16
    相关资源
    最近更新 更多