Jump to content

[SOLVED] If/else Statement help


twilitegxa

Recommended Posts

I want to write an if/else statement that checks the value of a field named "primary_attack" and if it is "1", then this calculation is done:

 

$sub_attribute_names_points * $attack_level (I have this currently in my statement)

 

The part I need to add is this:

 

If "secondary attack" = 1, $attack points = 2

If both "primary_attack" and "secondary_attack" = 0, $attack_points = 1

 

How can I write this if statement?

 

Here is my current code:

 

//gather attacks
$get_attacks = "select * from attacks where identity = '$identity' order by level desc";
$get_attacks_res = mysql_query($get_attacks, $conn) or die(mysql_error());

while ($attacks_info = mysql_fetch_array($get_attacks_res)) {
$attack_id = $attacks_info['id'];
$attack_identity = $attacks_info['identity'];
$attack = $attacks_info['attack'];
$primary = $attacks_info['primary_attack'];
$secondary = $attacks_info['secondary_attack'];
$attack_level = $attacks_info['level'];
$attack_points = ($sub_attribute_names_points * $attack_level);

$display_block .= "
<tr>
<td class=indent>$sub_attribute_names_attribute</td>";

if ($sub_attribute_names_attribute == 'Sailor Scout Attack') {
$display_block .= "
<tr>
<td class=indent2>- $attack</td>
<td class=align_levels>$attack_level</td>
<td class=align_levels>$attack_points</td>
</tr>
<tr>";
}

Link to comment
https://forums.phpfreaks.com/topic/170866-solved-ifelse-statement-help/
Share on other sites

How can I write this if statement?

 

In almost the same way as you explained it

if "secondary attack" = 1, $attack points = 2

If both "primary_attack" and "secondary_attack" = 0, $attack_points = 1

 

if($secondary == 1) $attack_points = 2;
elseif($primary == 0 && $secondary == 0) $attack_points = 1;

 

 

Thank you! Tried writing it similar to what you wrote, but I had something wrong. I'm still learning how to do if/else statements! I had || instead of && for one thing, and I didn't have elseif, I had else if. I basically had it written like this:

 

if ($secondary == '1') {

$attack_points = '2'

} else if ($primary == '0' || $secondary == '0') {

$attack_points = '1'

} else {

$attack_points = ($sub_attribute_names_points * $attack_level);

}

 

See, my logic was a little off. Hopefully with more practice, I will start to get it.  :)

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.