facarroll Posted March 16, 2011 Share Posted March 16, 2011 This code returns part but not all of what I'm asking it to do. Variable $av1 is drawn from the database and always has a value of 1 or 0 (tinyint). If value is 1 a green ON is displayed and if 0 a red OFF is displayed. That works. The variable $group1 exists or not, and if exists the code should proceed and if not exist there should be a display of "". In other words, I do not want to see any display if $group1 does not exist, but this is not working. There is always a display. Can anyone point out my mistake? <?php if($group1 != "") { { echo "<input type='radio' name='1' value='$group1' />"; ?> <?php echo $group1; } ?> is switched <?php if($group1 != "") if($av1 !== 0) echo ("<span style=\"color:#080\">ON</span>"); else echo ("<span style=\"color:#F00\">OFF</span>"); }else{ echo ""; } ?> Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 16, 2011 Share Posted March 16, 2011 Before we get into the errors, what are the possible values if $group1? Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 16, 2011 Share Posted March 16, 2011 Try... <?php if(strlen(trim($group1))<1){ /* display nothing */ }else{ echo "<input type='radio' name='1' value='$group1' />"; ?> <?php echo $group1; ?> is switched <?php if($av1 == 1){ echo ("<span style=\"color:#080\">ON</span>"); }else{ echo ("<span style=\"color:#F00\">OFF</span>"); } } ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 16, 2011 Share Posted March 16, 2011 It seems like you have an extra curly bracket in the beginning: <?php if($group1 != "") { { //<--- REMOVE THIS BRACKET ... ?> But that doesn't seem to be an issue. I also think you need to add a curly bracket: <?php ... if($group1 != "") { //<--- ADD THE BRACKET HERE if($av1 !== 0) echo ("<span style=\"color:#080\">ON</span>"); else echo ("<span style=\"color:#F00\">OFF</span>"); }else{ echo ""; } ?> Note sure if that will fix the problem, but it seems to work on my end. Quote Link to comment Share on other sites More sharing options...
facarroll Posted March 16, 2011 Author Share Posted March 16, 2011 Thanks for your contributions everyone, but nothing works so far. Litebearer, FYI $group1 is one of a selection of six variables that are simply strings (varchar) contributed by a subscriber, however it is only necessary that $group1 is set, because the subscriber may only want to use one group. I don't think that is an issue, but I have been struggling to get the curly braces correct. If I restate the problem with an example it might help. I have an output that is displayed six times according to the variables $group1 ... $group 6 and variables $av1 ... $av6 will always have a variable of 1 (representing ON) or 0 (representing OFF). If the group represented by $group? does not exist, then there should be no display for that line. When the $group? does exist, then I want to display a line like this for each existing group, depending on whether $av? is a 1 or a 0. (ON or OFF). "radio button image" Group name is switched ON or "radio button image" Group name is switched OFF The display of the above coloured text works fine, but the whole display always exists when it should sometimes actually be absent if there is no value (does not exist) for the $group? variable in the database. Now you know why my head hurts. Quote Link to comment Share on other sites More sharing options...
facarroll Posted March 16, 2011 Author Share Posted March 16, 2011 I got it with this; <?php if($group1 != "") {{echo "<input type='radio' name='1' value='$group1' />"; ?> <?php echo $group1; }?> is switched <?php if($group1 != "") if($av1 !== 0) echo ("<span style=\"color:#080\">ON</span>"); else echo ("<span style=\"color:#F00\">OFF</span>");}else{echo"";}?> Thanks everyone. Quote Link to comment Share on other sites More sharing options...
facarroll Posted March 16, 2011 Author Share Posted March 16, 2011 How do I mark this solved? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 16, 2011 Share Posted March 16, 2011 How do I mark this solved? Last I heard, the forum software used by PHP Freaks was upgraded and the "solved" mod wasn't compatible with the new version. I don't know if they found an alternative solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.