twilitegxa Posted August 18, 2009 Share Posted August 18, 2009 How do I make the $sub_attributes_points display as blank or nothing if the calculation returns a value of "0"? Here is the code I have: $get_sub_attribute_names = "select * from sub_attributes where id = '$sub_attributes_attribute_id'"; $get_sub_attribute_names_res = mysql_query($get_sub_attribute_names, $conn) or die(mysql_error()); while ($sub_attribute_names_info = mysql_fetch_array($get_sub_attribute_names_res)) { $sub_attribute_names_id = $sub_attribute_names_info['id']; $sub_attribute_names_attribute = $sub_attribute_names_info['sub_attribute']; $sub_attribute_names_points = $sub_attribute_names_info['points']; $sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id); $display_block .= " <tr> <td class=indent>$sub_attribute_names_attribute</td> <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/170891-solved-return-blank-if-value-of-calculation-is-0/ Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 change <td class=align_levels>$sub_attributes_points</td> to <td class=align_levels><?php echo ($sub_attributes_points == 0) ? "" : $sub_attributes_points; ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/170891-solved-return-blank-if-value-of-calculation-is-0/#findComment-901335 Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 I received this error when I changed that: Parse error: parse error in C:\wamp\www\showprofile_scouts.php on line 370 Isn't it a problem using the <?php ?> tags within this code because it is already in php tags? How else can I do it? I had to do the same thing before, but I used an if statement, but I'm not sure how I'd do it here. Here is one I used before: if($health == 0 || $health == '0' || $health == null){$GLOBALS['health'] = "";} But since this one isn't from a value in the table, I don't know how i'd write it. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/170891-solved-return-blank-if-value-of-calculation-is-0/#findComment-901376 Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 Well, I did this and it worked: $get_sub_attributes = "select * from scout_sub_attributes where identity = '$identity'"; $get_sub_attributes_res = mysql_query($get_sub_attributes, $conn) or die(mysql_error()); while ($sub_attributes_info = mysql_fetch_array($get_sub_attributes_res)) { $sub_attributes_id = $sub_attributes_info['id']; $sub_attributes_identity = $sub_attributes_info['identity']; $sub_attributes_attribute_id = $sub_attributes_info['sub_attribute_id']; $sub_attributes_level_id = $sub_attributes_info['level_id']; $sub_attributes_notes = $sub_attributes_info['notes']; $get_sub_attribute_names = "select * from sub_attributes where id = '$sub_attributes_attribute_id'"; $get_sub_attribute_names_res = mysql_query($get_sub_attribute_names, $conn) or die(mysql_error()); while ($sub_attribute_names_info = mysql_fetch_array($get_sub_attribute_names_res)) { $sub_attribute_names_id = $sub_attribute_names_info['id']; $sub_attribute_names_attribute = $sub_attribute_names_info['sub_attribute']; $sub_attribute_names_points = $sub_attribute_names_info['points']; $sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id); $display_block .= " <tr> <td class=indent>$sub_attribute_names_attribute</td>"; if ($sub_attributes_level_id == null) { $display_block .= "$sub_attributes_level_id"; } else { $display_block .= " <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } I just added that if statement and it fixed the problem. Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/170891-solved-return-blank-if-value-of-calculation-is-0/#findComment-904274 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.