2015-06-29 21 views
-6

你好,我正在用php構建一個簡單的計算機。
它應該以這樣的方式工作,即當用戶選擇大於30的數字時,變量(在本例中爲m1)變爲m2等等。
我該如何做到這一點?
預先感謝您php計算器開關乘法器基於輸入

<?php 
    $m1 = 5 /*prezzo della maglia - price 1*/; 
    $m2 = 2;/*price when quantity is over a number*/ 
    $m3 = 1;/*price when quantity is over a number*/ 

    $s1 = 3; /*price of print 1*/ 
    $s1 = 3; /*price of print 1 if quantity change*/ 

    $bxs = $_GET['bxs']; 
    $bs = $_GET['bs']; 
    $bm = $_GET['bm']; 
    $bl = $_GET['bl']; 
    $bxl = $_GET['bxl']; 
    $b2xl = $_GET['b2xl']; 
    /*riga del nero*/ 
    $nxs = $_GET['nxs']; 
    $ns = $_GET['ns']; 
    $nm = $_GET['nm']; 
    $nl = $_GET['nl']; 
    $nxl = $_GET['nxl']; 
    $n2xl = $_GET['n2xl']; 

$somma = $m1*($bxs+$bs+$bm+$bl+$bxl+$b2xl+$nxs+$ns+$nm+$nl+$nxl+$n2xl); 
?> 
+1

如何用戶可以選擇的值? – Toumash

+0

這是我的html測試[鏈接](http://creami.altervista.org/)不看錶少,愛在用戶輸入表中的值然後按照總數,這意味着如果任何表格包含100件,將會有100 –

+0

的價格不清楚你想要達到什麼。我向你介紹了if語句,buisness登錄在你身邊 – Toumash

回答

1

這很簡單,但你必須提供用戶的方式輸入該值。

例如由GET參數number
$userInput = $_GET['number'];

然後你只需要建立基本的if語句。你可以在http://php.net/manual/en/control-structures.if.php

$somma = $bxs+$bs+$bm+$bl+$bxl+$b2xl+$nxs+$ns+$nm+$nl+$nxl+$n2xl; 
if($userInput <= 30){ 
    $somma *=$m1; 
}else if($userInput >30) { 
    $somma *=$m2; 
} else if($userInput > 8779){ // your number :) 
    $somma *=$m3; 
} 
+0

謝謝。當回到辦公室時,我嘗試你的解決方案 –

+0

ho seguito我Tuoi Consigli ma $ 3 ad esempio non viene calcolata,mi sa che e meglio farlo eseguire da js ... –