Jump to content


Putting query results in arrays

  • Please log in to reply
1 reply to this topic

#1 Haden

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 March 2006 - 09:10 PM

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:
$stats = array(
foreach($stats != '0')
echo '<tr><td width=150>, '$lck, '</td><td>', $lck, '</td></tr>';

It was to take place of this...:

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>';}

#2 Haden

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 March 2006 - 09:31 PM

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...
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>';}

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users