Jump to content

[SOLVED] If statement not working


twilitegxa

Recommended Posts

I have the following if statement, but it's not displaying anything. What am I doing wrong? I have another if statement just like it working perfectly. What am I missing?

 

$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'];

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

}
}

//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);

//checks for primary and secondary attacks
if($secondary == 1) $attack_points = 2;
elseif($primary == 0 && $secondary == 0) $attack_points = 1;

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

}
}

//gather items of power
$get_items = "select * from items where identity = '$identity'";
$get_items_res = mysql_query($get_items, $conn) or die(mysql_error());

while ($items_info = mysql_fetch_array($get_items_res)) {
$items_id = $items_info['id'];
$items_identity = $items_info['identity'];
$item = $items_info['item'];
$item_level = $items_info['level'];
$item_points = ($sub_attribute_names_points * $item_level);

if ($sub_attribute_names_attribute == 'Item Of Power') {
$display_block .= "
<tr>
<td class=indent2>- $item</td>
<td class=align_levels>$item_level</td>
<td class=align_levels>$item_points</td>
</tr>";

}
}

[/code

The part that isn't working right is the if statement at the end, for the items table (where is says, gather the items of power). What am I doing wrong?

Link to comment
Share on other sites

Maybe try using echo to echo the value of

$sub_attribute_names_attribute

 

of course this assumes your queries are okay and $identity is being set..

 

to help out I cleaned up the formatting a little

 

<?php
$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'];

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

}
}

//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);

//checks for primary and secondary attacks
if ($secondary == 1)
	$attack_points = 2;
elseif ($primary == 0 && $secondary == 0)
	$attack_points = 1;

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

}
}

//gather items of power
$get_items = "select * from items where identity = '$identity'";
$get_items_res = mysql_query ( $get_items, $conn ) or die ( mysql_error () );

while ( $items_info = mysql_fetch_array ( $get_items_res ) ) {
$items_id = $items_info ['id'];
$items_identity = $items_info ['identity'];
$item = $items_info ['item'];
$item_level = $items_info ['level'];
$item_points = ($sub_attribute_names_points * $item_level);

if ($sub_attribute_names_attribute == 'Item Of Power') {
	$display_block .= "
<tr>
<td class=indent2>- $item</td>
<td class=align_levels>$item_level</td>
<td class=align_levels>$item_points</td>
</tr>";

}
}
?>

Link to comment
Share on other sites

Echo it where? It is listing all of the records in the sub_attributes_names table and the previous if statement lists the attacks if the sub_attribute_name equals "Sailor Scout Attack" so I can't see why it won't pull the items if the sub_attribute_name equals "Item Of Power". Have I typed something wrong that anyone can see?

Link to comment
Share on other sites

I tried moving the items above the attacks statement, and then commentign out the if statement to see what was printing and how it was printing, and all of the items get listed like I want them to, except theya re getting listed with the attacks, under the Sailor Scout Attack. Here is the code:

 

$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>
<td class=align_levels>$sub_attributes_level_id</td>
<td class=align_levels>$sub_attributes_points</td>
</tr>";

}
}

//gather items of power
$get_items = "select * from items where identity = '$identity'";
$get_items_res = mysql_query($get_items, $conn) or die(mysql_error());

while ($items_info = mysql_fetch_array($get_items_res)) {
$items_id = $items_info['id'];
$items_identity = $items_info['identity'];
$item = $items_info['item'];
$item_desc = $items_info['desc'];
$item_level = $items_info['level'];
$item_points = ($sub_attribute_names_points * $item_level);

//if ($sub_attribute_names_attribute == 'Item Of Power') {
$display_block .= "
<tr>
<td class=indent2>- $item</td>
<td class=align_levels>$item_level</td>
<td class=align_levels>$item_points</td>
</tr>
<tr>";

}
//}

//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);

//checks for primary and secondary attacks
if($secondary == 1) $attack_points = 2;
elseif($primary == 0 && $secondary == 0) $attack_points = 1;

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

}
}

 

How can I fix my if statement to make it print out the items under the Item Of Power?

Link to comment
Share on other sites

I figured it out! I moved the items statement to be inside of the sub_attributes loop, and now it works. Here is the code:

 

$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>
<td class=align_levels>$sub_attributes_level_id</td>
<td class=align_levels>$sub_attributes_points</td>
</tr>";

//gather attacks
$get_items = "select * from items where identity = '$identity' order by level asc";
$get_items_res = mysql_query($get_items, $conn) or die(mysql_error());

while ($items_info = mysql_fetch_array($get_items_res)) {
$item_id = $items_info['id'];
$item_identity = $items_info['identity'];
$items = $items_info['item'];
$item_desc = $items_info['desc'];
$item_level = $items_info['level'];
$item_points = ($sub_attribute_names_points * $item_level);

if ($sub_attribute_names_attribute == 'Item Of Power') {
$display_block .= "
<tr>
<td class=indent2>- $items</td>
<td class=align_levels>$item_level</td>
<td class=align_levels>$item_points</td>
</tr>
<tr>";

}
}

}
}



//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);

//checks for primary and secondary attacks
if($secondary == 1) $attack_points = 2;
elseif($primary == 0 && $secondary == 0) $attack_points = 1;

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

}
}

 

Thanks for all the help everyone!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.