我疯了,因为我无法弄清楚.. 我正在创建一个代码,告诉我将打印多少个面板。
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大小时)。 我需要这个变量&#34; $ base&#34;是从输入字段中获取并实时更新的,我该怎么做?
答案 0 :(得分:0)
设置$ 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";
}
?>