MarcP Posted June 29, 2008 Share Posted June 29, 2008 On an "if" statement should the variables be put in parenthesis?? In an application that I wrote, the user will input information. That information will be calculated to determine the outcome. I know it's confusing. Here's a piece of code,if ($difference == 5 && $targetcolor == 10 && $tone == GB)I know it's not complete the way it is, I just took a piece that I had. The number "5" is the difference between 2 variables, $difference = $targetcolor – $existinglevel;Should the "5" the "10" and the "GB" be put in single or double quotations?Also, do I need the parenthesis, I know that Deidre's dad says that it's not a bad practice but I was just wondering.Do I need separate quotation around the text and the variables?? echo ("<b>Control for excessive warmth:</b> $cntrlamount. " " .$cntrl <p> " );Thank you in advanceMarc Link to comment Share on other sites More sharing options...
Ingolme Posted June 29, 2008 Share Posted June 29, 2008 You only put quotes (whether single or double) around strings. A string is text data.A number doesn't need quotes, in fact, if it has quotes it's not a number anymore.So your if command should look like this:if ($difference == 5 && $targetcolor == 10 && $tone == "GB")You can't have two strings on the same line without some kind of operator between them. Your echo statement is incorrect.You usually only need to open and close the quotes once within a string. If you decide to do something else, then you use a concatenating operater (a dot):echo ("<b>Control for excessive warmth:</b> {$cntrlamount} {$cntrl} <p> " );ORecho ("<b>Control for excessive warmth:</b>" . $cntrlamount . " " . $cntrl . "<p> " ); Link to comment Share on other sites More sharing options...
MarcP Posted July 2, 2008 Author Share Posted July 2, 2008 Thank you Inglomethats what I was looking for.Marc Link to comment Share on other sites More sharing options...
MarcP Posted July 3, 2008 Author Share Posted July 3, 2008 Then should you use concatenating in a situation like this;if ( $ns == "15 mls" && .$targetcolor. && "N" ) {$trgtclramount = "25 mls ";echo $trgtclramount;}or would it be better to put brackets around it like this;if ( ($ns == "15 mls") && ($targetcolor) && "N" ) {$trgtclramount = "25 mls ";echo $trgtclramount;}thanks for the previous quick responseMarc Link to comment Share on other sites More sharing options...
jeffman Posted July 3, 2008 Share Posted July 3, 2008 This one makes no sense. Don't do this. if ( $ns == "15 mls" && .$targetcolor. && "N" ) {$trgtclramount = "25 mls ";echo $trgtclramount;} This one makes sense, but only if you're testing that $targetcolor has a value and "N" exists, which of course it does, so mostly it doesn't make sense. if ( ($ns == "15 mls") && ($targetcolor) && "N" ) {$trgtclramount = "25 mls ";echo $trgtclramount;} Do you mean if ( ($ns == "15 mls") && ($targetcolor == "N" ) )or maybe if ( $ns == "15 mls" . $targetcolor . "N" )in other words, if $ns == a big string assembled from 3 pieces? Link to comment Share on other sites More sharing options...
MarcP Posted July 4, 2008 Author Share Posted July 4, 2008 what was I thinking??Thank you Deirdre's dad, the second example, if ( $ns == "15 mls" . $targetcolor . "N" )is what I need.I have several long strings and this will make things smootherThanx Marc Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.