Pergunta

I'm going crazy because I can not figure it out .. I'm creating a code that tells me how many panels will be split my printing.

The PHP code is this:

<?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";
}

?>

This code works perfectly (when i cange the $base size manually). I need this variable "$base" is taken from an input field and updated in real time, how can i do that?

Foi útil?

Solução

set $base = $_GET['base'],and your url like this: test.php?base=400 it will work well.

another way is to build a form ,which has a that let you input $base ,either by post or by get,then you can ues $base.

hope these help you~~

<?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";
}

?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top