twilitegxa Posted August 18, 2009 Share Posted August 18, 2009 How can I make the $sub_attributes_name_attribute table row not repeat as the $attacks get listed under the "Sailor Scout Attack"? I have: $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']; //gather attacks $get_attacks = "select * from attacks where identity = '$identity'"; $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']; $attack_level = $attacks_info['level']; $display_block .= " <tr> <td class=indent>$sub_attribute_names_attribute</td>"; if ($sub_attribute_names_attribute == 'Sailor Scout Attack') { $display_block .= " <tr> <td>$attack</td> <td>$attack_level</td> <td> </td> </tr>"; } $display_block .= " <td>$sub_attributes_level_id</td> <td> </td> </tr>"; } } } And the "$attacks" are being output as expected, but the $sub_attributes_names_attribute" row is repeating, which I do not want. Here is an image: See how it is repeating? This is how it should look: And each "attack" should be listed and then the rest of the "$sub_attribute_names_attribute" should be listed afterwards. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 18, 2009 Share Posted August 18, 2009 all your brackets seem to be all at the end so it keeps looping until you close it. hopefully ordering the brackets correctly solves this. <?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']; } //gather attacks $get_attacks = "select * from attacks where identity = '$identity'"; $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']; $attack_level = $attacks_info['level']; } $display_block .= " <tr> <td class=indent>$sub_attribute_names_attribute</td>"; if ($sub_attribute_names_attribute == 'Sailor Scout Attack') { $display_block .= " <tr> <td>$attack</td> <td>$attack_level</td> <td> </td> </tr>"; } $display_block .= " <td>$sub_attributes_level_id</td> <td> </td> </tr>"; ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 Changing to that code stop the repeating, but it made only one of the "sailor scout attack" records show. I have also added a few new statements, so here is the new code, still with the same problem: $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); //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']; $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>"; } $display_block .= " <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } } } One of the problems is that your code only got the one record from the attacks table and displayed it but no others. The way you did it only got of of the records from the sailor scout attacks, but it did stop the others from repeating, but also did not give any other sub_attributes after the sailor scout attack. It only shows the Sailor Scout Attack and one attack record. It does not show any other sub_attribute records or any other attack. Here is what it does from your code: Here is another couple images of what it is doing, so you can see the problem: The part that starts with "Acorbatics" is where the neutral_attributes start. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 18, 2009 Share Posted August 18, 2009 okay i figured it out, you have the same loop twice it is not needed. just make it one loop Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 Which one do I have twice? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 18, 2009 Share Posted August 18, 2009 $sub_attributes_name_info that loop is run twice look at your code Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 I don't see where it's running twice? Are you sure? Here is my full code: <?php session_start(); //Access Tracking Snippet //set up static variables $page_title = "showprofile.php"; $user_agent = getenv("HTTP_USER_AGENT"); $date_accessed = date("Y-m-d"); //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("smrpg", $conn) or die(mysql_error()); //create and issue query $sql = "insert into access_tracker values ('', '$page_title', '$user_agent', '$date_accessed')"; mysql_query($sql,$conn); ?> <?php //check for required info from the query string if (!$_GET['id']) { header("Location: listcharacters.php"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg", $conn) or die(mysql_error()); //verify the topic exists $verify_topic = "select identity from scouts where id = $_GET[id]"; $verify_topic_res = mysql_query($verify_topic, $conn) or die(mysql_error()); if (mysql_num_rows($verify_topic_res) < 1) { //this character does not exist $display_block = "<p><em>You have selected an invalid character. Please <a href=\"listcharacters.php\">try again</a></em></p>"; } else { //gather rest of profile $get_posts = "select *, date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time from scouts where id = $_GET[id]"; $get_posts_res = mysql_query($get_posts, $conn) or die(mysql_error()); //create the display string $display_block = " <table cellpadding=3 cellspacing=1 border=1>"; while ($posts_info = mysql_fetch_array($get_posts_res)) { $post_id = $posts_info['id']; $identity = ucwords($posts_info['identity']); $character_create_time = $posts_info['fmt_scout_create_time']; $username = $posts_info['username']; $name = ucwords(strtolower($posts_info['name'])); $element_of_influence = $posts_info['element_of_influence']; $age = $posts_info['age']; $birth_month = $posts_info['birth_month']; $birth_date = $posts_info['birth_date']; $birth_year = $posts_info['birth_year']; $height_feet = $posts_info['height_feet']; $height_inches = $posts_info['height_inches']; $blood_type = strtoupper($posts_info['blood_type']); $hobbies = ucwords(strtolower($posts_info['hobbies'])); $favorite_color = ucwords(strtolower($posts_info['favorite_color'])); $favorite_gemstone = ucwords(strtolower($posts_info['favorite_gemstone'])); $favorite_food = ucwords(strtolower($posts_info['favorite_food'])); $least_favorite_food = ucwords(strtolower($posts_info['least_favorite_food'])); $favorite_school_subject = ucwords(strtolower($posts_info['favorite_school_subject'])); $least_favorite_school_subject = ucwords(strtolower($posts_info['least_favorite_school_subject'])); $strengths = ucwords(strtolower($posts_info['strengths'])); $weaknesses = ucwords(strtolower($posts_info['weaknesses'])); $goal = ucfirst($posts_info['goal']); $mission = ucfirst($posts_info['mission']); $biography = nl2br($posts_info['biography']); $biography = str_replace("\n", "<p>", $biography ); $getMonth = date('F', mktime(0, 0, 0, $birth_month)); //add to display $display_block .= " <tr> <td width=24% valign=top><strong>Character Name:</strong></td> <td width=55% valign=top>$name</td> <td align=center valign=top rowspan=18><img src=\"image.gif\" height=\"500\" width=\"200\"></td> </tr> <tr> <td><strong>Element Of Influence:</strong></td> <td>$element_of_influence</td> </tr> <tr> <td><strong>Age:</strong></td> <td>$age</td> </tr> <tr> <td><strong>Date Of Birth:</strong></td> <td>$getMonth $birth_date, $birth_year</td> </tr> <tr> <td><strong>Height:</strong></td> <td>$height_feet feet $height_inches inches</td> </tr> <tr> <td><strong>Blood Type:</strong></td> <td>$blood_type</td> </tr> <tr> <td><strong>Hobbies:</strong></td> <td>$hobbies</td> </tr><tr> <td><strong>Favorite Color:</strong></td> <td>$favorite_color</td> </tr> <tr> <td><strong>Favorite Gemstone:</strong></td> <td>$favorite_gemstone</td> </tr> <tr> <td><strong>Favorite Food:</strong></td> <td>$favorite_food</td> </tr> <tr> <td><strong>Least Favorite Food:</strong></td> <td>$least_favorite_food</td> </tr> <tr> <td><strong>Favorite School Subject:</strong></td> <td>$favorite_school_subject</td> </tr> <tr> <td><strong>Least Favorite School Subject:</strong></td> <td>$least_favorite_school_subject</td> </tr> <tr> <td><strong>Strengths:</strong></td> <td>$strengths</td> </tr> <tr> <td><strong>Weaknesses:</strong></td> <td>$weaknesses</td> </tr> <tr> <td><strong>Goal:</strong></td> <td>$goal...</td> </tr> <tr> <td><strong>Mission:</strong></td> <td>$mission.</td> </tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td valign=left>Created By: $username<br> Created On: [$character_create_time]</td> </tr>"; } //close up the table $display_block .= "</table><br> <p>$biography</p><br>"; } //gather stats and derived values; fix where statement $get_stats = "select * from stats where identity = 'Sailor Moon'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); $display_block .= " <table cellpadding=3 cellspacing=3 border=1 width=100%>"; while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; $display_block .= " <tr> <td valign=top> <table cellspacing=3 cellpadding=3 border=1 width=60% align=center> <th colspan=3>Stats And Derived Values</th> <tr> <td><b>Body</b></td> <td class=align_levels>$body</td> <td> </td> </tr> <tr> <td><b>Mind</b></td> <td class=align_levels>$mind</td> <td> </td> </tr> <tr> <td><b>Soul</b></td> <td class=align_levels>$soul</td> <td> </td> </tr>"; } //gather derived values $get_derived = "select * from derived_values where identity = '$identity'"; $get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error()); while ($derived_info = mysql_fetch_array($get_derived_res)) { $health = $derived_info['health']; $energy = $derived_info['energy']; $acv1 = $derived_info['acv1']; $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)'; $dcv1 = $derived_info['dcv1']; $dcv2 = $derived_info['dcv2'] . ' (for Sailor Scout Attack)'; $total_cp = $derived_info['total_cp']; if($health == 0 || $health == '0' || $health == null){$GLOBALS['health'] = "";} if($energy == 0 || $energy== '0' || $energy == null){$GLOBALS['energy'] = "";} if($acv1 == 0 || $acv1 == '0' || $acv1 == null){$GLOBALS['acv1'] = "";} if($acv2 == 0 || $acv2 == '0' || $acv2 == null){$GLOBALS['acv2'] = "";} if($dcv1 == 0 || $dcv1 == '0' || $dcv1 == null){$GLOBALS['dcv1'] = "";} if($dcv2 == 0 || $dcv2 == '0' || $dcv2 == null){$GLOBALS['dcv2'] = "";} if($total_cp == 0 || $total_cp == '0' || $total_cp== null){$GLOBALS['total_cp'] = "";} $display_block .= " <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><b>Health Points</b></td> <td class=align_levels>$health</td> <td> </td> </tr> <tr> <td><b>Energy Points</b></td> <td class=align_levels>$energy</td> <td> </td> </tr> <tr> <td><b>Attack Combat Value</b></td> <td class=align_levels>$acv1</td> <td>$acv2</td> </tr> <tr> <td><b>Defense Combat Value</b></td> <td class=align_levels>$dcv1</td> <td>$dcv2</td> </tr> <tr> <td><b>Total Character Points</b></td> <td class=align_levels>$total_cp</td> <td> </td> </tr> </table><br>"; } //gather defects $get_defects = "select * from scout_defects where identity = '$identity'"; $get_defects_res = mysql_query($get_defects, $conn) or die(mysql_error()); $display_block .= " <table cellpadding=3 cellspacing=3 border=1 width=60% align=center> <th colspan=2>Character Defects</th>"; while ($defects_info = mysql_fetch_array($get_defects_res)) { $defects_id = $defects_info['id']; $defects_identity = $defects_info['identity']; $defects_id = $defects_info['defect_id']; $desc = $defects_info['desc']; $defects_level = $defects_info['level']; if($defects_info['desc'] != ""){ $desc = "(" . $defects_info['desc'] . ")"; }else{ $desc = ""; } $get_defects_names = "select * from defects where id = '$defects_id'"; $get_defects_names_res = mysql_query($get_defects_names, $conn) or die(mysql_error()); while ($defects_names_info = mysql_fetch_array($get_defects_names_res)) { $defects_names_id = $defects_names_info['id']; $defect = $defects_names_info['defect']; $display_block .= " <tr> <td>$defect $desc</td> <td>$defects_level</td> </tr>"; } } $display_block .= " </table></td>"; // gather attributes and sub-attributes $get_attributes = "select * from scout_attributes where identity = '$identity'"; $get_attributes_res = mysql_query($get_attributes, $conn) or die(mysql_error()); $display_block .= " <td valign=top> <table cellspacing=3 cellpadding=3 border=1 width=60% align=center> <th colspan=3>Character Attributes And Sub-Attributes</th> <tr> <td class=align_levels><b>Attribute/Sub-Attribute</b></td> <td class=align_levels><b>Level</td> <td class=align_levels><b>Points</b></td> </tr>"; while ($attributes_info = mysql_fetch_array($get_attributes_res)) { $attributes_id = $attributes_info['id']; $attribute_identity = $attributes_info['identity']; $attribute_id = $attributes_info['attribute_id']; $attribute_level = $attributes_info['level_id']; $get_attribute_names = "SELECT * FROM attributes WHERE id = '$attribute_id'"; $get_attribute_names_res = mysql_query($get_attribute_names, $conn) or die(mysql_error()); while ($attribute_names_info = mysql_fetch_array($get_attribute_names_res)) { $attribute_names_id = $attribute_names_info['id']; $attribute_names_attribute = $attribute_names_info['attribute']; $attributes_names_points = $attribute_names_info['points']; $attributes_points = ($attributes_names_points * $attribute_level); $display_block .= " <tr> <td>$attribute_names_attribute</td> <td class=align_levels>$attribute_level</td> <td class=align_levels>$attributes_points</td> </tr>"; } } $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); //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']; $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>"; } $display_block .= " <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } } } //gather neutral attributes $get_neutral_attributes = "select * from scout_neutral_attributes where identity = '$identity'"; $get_neutral_attributes_res = mysql_query($get_neutral_attributes, $conn) or die(mysql_error()); while ($neutral_attributes_info = mysql_fetch_array($get_neutral_attributes_res)) { $neutral_attributes_id = $neutral_attributes_info['id']; $neutral_attributes_identity = $neutral_attributes_info['identity']; $neutral_attributes_attribute_id = $neutral_attributes_info['attribute_id']; $neutral_attributes_level_id = $neutral_attributes_info['level_id']; $get_neutral_attribute_names = "select * from neutral_attributes where id = '$neutral_attributes_attribute_id'"; $get_neutral_attribute_names_res = mysql_query($get_neutral_attribute_names, $conn) or die(mysql_error()); while ($neutral_attribute_names_info = mysql_fetch_array($get_neutral_attribute_names_res)) { $neutral_attribute_names_id = $neutral_attribute_names_info['id']; $neutral_attribute_names_attribute = $neutral_attribute_names_info['attribute']; $display_block .= " <tr> <td>$neutral_attribute_names_attribute</td> <td class=align_levels>$neutral_attributes_level_id</td> <td class=align_levels> </td> </tr>"; } } $display_block .= " </table></td></tr></table>"; ?> <html> <head> <title><?php print $identity; ?>'s Profile</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1 align="center"><?php print $identity; ?></h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html> I didn't see it anywhere in the part I posted before. Is it in the full code or the partial from earlier? Where is it at? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 18, 2009 Share Posted August 18, 2009 <?php switch($sub_attribute_names_attribute) { case(mysql_num_rows($sub_attribute_names_attribute )>1): echo " you have a duplicate entry"; break; default: echo "no duplicate entries"; } ?> also your loops should look like this <?php while($variable=mysql_fetch_array($variable2)) { // variables here plus output }?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 I thought that was how I had my loops? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 18, 2009 Share Posted August 18, 2009 not really you end your loops all at once which is probably causing it to loop more than once. like i said it needs you need to call all your code you want inside the loop then close it after not all at once. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 $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); //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; $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>"; } $display_block .= " <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } } } [code] Okay, so firstly, don't I need to have my first loop to end at the very end because I want the loop to continue until the sub_attribute_names and attack loops have ended? Then I need the sub_attribute_names one to continue until after the attacks loop, so I figure it also needs to be at the end, with the sub_attributes loop. I tried changing the attacks loo and ending it before the sub_attributes_levels, but ti didn't seem to change anything. I'm not sure where I need to end which loops. If I end the loops too early, I won't get all of the results I need. I am so lost! Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2009 Author Share Posted August 18, 2009 Nevermind, I figured out the problem. I ended my loops for sub_attributes and sub_attribute_names and then added the attacks if statement and then the attacks loop and it works now perfectly! Here's 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']; $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>"; } } Thanks for your help! What you pointed out made me able to figure it out! Thank you so much! 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.