samedi 27 juin 2015

PHP multiple conditions for if statement that changes font color

I've some problems with this PHP code:

 // HIGHLIGHT NUMBERS *************************************************
 // BUY
$valueEnlightOverBuy = $_POST["enlightOverBuy"];
$valueEnlightUnderBuy = $_POST["enlightUnderBuy"];

// GREEN PRICE BUY
$fontColorBuy = "#FFF"; 

    if ((($valueEnlightOverBuy != '') or ($valueEnlightUnderBuy != '')) and (($valueEnlightOverBuy and $valueEnlightUnderSell) != "0")) {
    if (($finalPriceBuyer >= $valueEnlightOverBuy) or ($finalPriceBuyer <= $valueEnlightUnderBuy)) {
    $fontColorBuy = "#00FF00";
    } else if (($finalPriceBuyer >= $valueEnlightOverBuy and $finalPriceBuyer <= $valueEnlightUnderBuy)) {
    $fontColorBuy = "#FF00FF";
    } else {
    $fontColorBuy = "#D00000";
    }};

 // SELL LOCAL
 $valueEnlightOverSloc = $_POST["enlightOverSloc"];
 $valueEnlightUnderSloc = $_POST["enlightUnderSloc"];

 // GREEN PRICE SELL LOCAL
 $fontColorSellLoc = "#FFF";    

    if ((($valueEnlightOverSloc != '') or ($valueEnlightUnderSloc != '')) & (($valueEnlightOverSloc & $valueEnlightUnderSloc) != "0")) {
    if (($finalPriceSellerLocal >= $valueEnlightOverSloc) or ($finalPriceSellerLocal <= $valueEnlightUnderSloc)) {
    $fontColorSellLoc = "#00FF00";
    } else if (($finalPriceSellerLocal >= $valueEnlightOverSloc) and ($finalPriceSellerLocal <= $valueEnlightUnderSloc)) {
    $fontColorSellLoc = "#FF00FF";
    } else {
    $fontColorSellLoc = "#D00000";
    }};

 // SELL INTERNATIONAL
 $valueEnlightOverSellInt = $_POST["enlightOverSellInt"];
 $valueEnlightUnderSellInt = $_POST["enlightUnderSellInt"];

 // GREEN PRICE SELL INTERNATIONAL
 $fontColorSellInt = "#FFF";    

    if ((($valueEnlightOverSellInt != '') or ($valueEnlightUnderSellInt  != '')) & (($valueEnlightOverSellInt & $valueEnlightUnderSellInt) != "0"))      {
    if (($finalPriceSellerInt >= $valueEnlightOverSellInt) or  ($finalPriceSellerInt <= $valueEnlightUnderSellInt)) {
    $fontColorSellInt = "#00FF00";
    } else if (($finalPriceSellerInt >= $valueEnlightOverSellInt) and  ($finalPriceSellerInt <= $valueEnlightUnderSellInt)) {
    $fontColorSellInt = "#FF00FF";
    } else {
    $fontColorSellInt = "#D00000";  
    }};

As you see I have a post form (not showed in code) that transmit to this file the values for: VAR underBuy < BUY PRICE < VAR overBuy; VAR underLocalSeller < LOCAL SELL PRICE < VAR overLocalSeller; VAR underIntSeller < INT SELL PRICE < VAR underIntSeller.

Firstly the code makes a check if the VAR received from form are EMPTY or = to 0; if it's not, the code collect all this data and make a check on $FINALPRICEBUYER (extracted from a file with json) for the 1st two VARs, than make a check on $FINALPRICESELLERLOCAL for the 3rd and the 4th VARs and so make a check on $FINALPRICESELLERINT for the 5th and the 6th VARs.

If $ FINALPRICEBUYER is between >= than 1st VAR or <= than 2nd VAR make font GREEN, else if $FINALPRICEBUYER between 3rd VAR and 4th VAR go VIOLET, else go RED.

The same for $FINALPRICESELLERLOCAL and $FINALPRICESELLERINT.

I did the first two conditions because user can insert one price limit or two.

Could you help me to understand what's I'm doing wrong? (Maybe it's only a metter of logic...)

Thx

Aucun commentaire:

Enregistrer un commentaire