furn355 Posted April 22, 2010 Share Posted April 22, 2010 So i'm still learning my way around queries and the such. I created something that works for my new attack system. Only thing is its about 50 lines when it could probably be 4 :P Any help optimizing would be greatly appreciated!! Thanks in advance so the code: // I use this to get each of the equipped items data! $attkweapon = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_primary']})"); $wep = mysql_fetch_array($attkweapon); $attkarmor = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_armor']})"); $arm = mysql_fetch_array($attkarmor); $attkoffhand = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_offhand']})"); $off = mysql_fetch_array($attkoffhand); $attkhead = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_head']})"); $head = mysql_fetch_array($attkhead); $attkmedal = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_medal']})"); $med = mysql_fetch_array($attkmedal); $attkattachment = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_attachment']})"); $att = mysql_fetch_array($attkattachment); $attklegs = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_legs']})"); $leg = mysql_fetch_array($attklegs); $attkfeet = $db->query("SELECT i.* FROM items i WHERE i.itmid IN({$ir['equip_feet']})"); $feet = mysql_fetch_array($attkfeet); AND i print it out like this for now The item name: the strength, defense and speed boosts. (all to be rearranged once the code is optimized!) ".$wep['itmname']." ".$wep['strength_boost']." ".$wep['defense_boost']." ".$wep['speed_boost']." ".$arm['itmname']." ".$arm['strength_boost']." ".$arm['defense_boost']." ".$arm['speed_boost']." ".$off['itmname']." ".$off['strength_boost']." ".$off['defense_boost']." ".$off['speed_boost']." ".$head['itmname']." ".$head['strength_boost']." ".$head['defense_boost']." ".$head['speed_boost']." ".$med['itmname']." ".$med['strength_boost']." ".$med['defense_boost']." ".$med['speed_boost']." ".$att['itmname']." ".$att['strength_boost']." ".$att['defense_boost']." ".$att['speed_boost']." ".$leg['itmname']." ".$leg['strength_boost']." ".$leg['defense_boost']." ".$leg['speed_boost']." ".$feet['itmname']." ".$feet['strength_boost']." ".$feet['defense_boost']." ".$feet['speed_boost']." ALso if $wep['itmname'] was == 0 How would i get it to print out "fists" Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted April 23, 2010 Share Posted April 23, 2010 ALso if $wep['itmname'] was == 0 How would i get it to print out "fists" $weapon = $wep['itmname'] == 0 ? 'Fists' : ''.$wep['itmname'].''; echo $weapon; Quote Link to comment Share on other sites More sharing options...
Lithium Posted April 23, 2010 Share Posted April 23, 2010 echo $weapon = ($wep['itmname']) ? $wep['itmname'] : 'Fists'; Same as Bama's though a bit cleaner! :) Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted April 23, 2010 Share Posted April 23, 2010 using in clause with list would considerably shorten the amount of queries right? Quote Link to comment Share on other sites More sharing options...
Danny696 Posted April 23, 2010 Share Posted April 23, 2010 echo $weapon = ($wep['itmname']) ? $wep['itmname'] : 'Fists'; << wouldnt work, try this: echo ($wep['itmname']) ? $wep['itmname'] : 'Fists'; Quote Link to comment Share on other sites More sharing options...
Djkanna Posted April 24, 2010 Share Posted April 24, 2010 echo $weapon = ($wep['itmname']) ? $wep['itmname'] : 'Fists'; << wouldnt work, try this: echo ($wep['itmname']) ? $wep['itmname'] : 'Fists'; The first would work fine! 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.