Jump to content

[SOLVED] Return blank if value of calculation is 0?


twilitegxa

Recommended Posts

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>";

}
}

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?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.