Haden Posted March 8, 2006 Share Posted March 8, 2006 Hi all, now that I've gotten my Complex query working with the help of phpfreaks members, I was hoping to clean up the code a bit, make it more,,,,... hmmmm, what's the word, Better...For instance with the following code, I'm pretty sure that there should be a way to set this mess up in an array, so I tried my luck, I FAILED, I tried several variations of array examples on Google, but to no avail. Here's what I tried:[code]$stats = array( 'ac'=>'$ac', 'aff_ac'=>'$aff_ac', 'avg_dmg'=>'$avg_dmg', 'hr'=>'$hr', 'dr'=>'$dr', 'hp'=>'$hp', 'mv'=>'$mv', 'str'=>'$str', 'ini'=>'$ini', 'wis'=>'$wis', 'dex'=>'$dex', 'con'=>'$con', 'cha'=>'$cha', 'lck'=>'$lck');foreach($stats != '0'){echo '<tr><td width=150>, '$lck, '</td><td>', $lck, '</td></tr>';}[/code]It was to take place of this...:[code]if($ac != 0){echo '<tr><td width=150>AC</td><td>', $ac, '</td></tr>';}if($aff_ac != 0){echo '<tr><td width=150>AFF_AC</td><td>', $aff_ac, '</td></tr>';}if($avg_dmg != 0){echo '<tr><td width=150>AVG_DMG</td><td>', $avg_dmg, '</td></tr>';}if($hr != 0){echo '<tr><td width=150>HR</td><td>', $hr, '</td></tr>';}if($dr != 0){echo '<tr><td width=150>DR</td><td>', $dr, '</td></tr>';}if($hp != 0){echo '<tr><td width=150>HP</td><td>', $hp, '</td></tr>';}if($mv != 0){echo '<tr><td width=150>MV</td><td>', $mv, '</td></tr>';}if($str != 0){echo '<tr><td width=150>STR</td><td>', $str, '</td></tr>';}if($ini != 0){echo '<tr><td width=150>INT</td><td>', $ini, '</td></tr>';}if($wis != 0){echo '<tr><td width=150>WIS</td><td>', $wis, '</td></tr>';}if($dex != 0){echo '<tr><td width=150>DEX</td><td>', $dex, '</td></tr>';}if($con != 0){echo '<tr><td width=150>CON</td><td>', $con, '</td></tr>';}if($cha != 0){echo '<tr><td width=150>CHA</td><td>', $cha, '</td></tr>';}if($lck != 0){echo '<tr><td width=150>LCK</td><td>', $lck, '</td></tr>';}[/code] Quote Link to comment Share on other sites More sharing options...
Haden Posted March 8, 2006 Author Share Posted March 8, 2006 I can see now that this isn't going to work, I'm not sure what I was thinking of, because the first section of each row has to have it's description, therefore, I'll have to create a row for each stat. What about where the description in the first segment stays the same though... it should be able to work in there...[code]if($dwarf > 0){echo '<tr><td width=150>Race</td><td>Dwarf</td></tr>';}if($halfelf > 0){echo '<tr><td width=150>Race</td><td>Half-Elf</td></tr>';}if($halfogre > 0){echo '<tr><td width=150>Race</td><td>Half-Ogre</td></tr>';}if($halforc > 0){echo '<tr><td width=150>Race</td><td>Half-Orc</td></tr>';}if($halftroll > 0){echo '<tr><td width=150>Race</td><td>Half-Troll</td></tr>';}if($human > 0){echo '<tr><td width=150>Race</td><td>Human</td></tr>';}[/code]Actually, you know what, that isn't going to work either... I don't guess there really is a better way to code it for those... Please go ahead and close this post. 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.