Check202 Posted May 12, 2014 Share Posted May 12, 2014 (edited) Hi there, I'm stepping in the deep end here for a first post. Being a newbie and all. Here goes however. I have a form where someone can compare the stats of one troop with another and see the difference. As an example below I've kept it to just two troops to be compared. Table name: Troops Columns: Name: Stat1: Stat2: Stat3 Medtronic 12 20 40 Tank 20 10 34 In the form the user selects Medtronic and Tank and wishes to know the differences in stats. So I have the $Result being Medtronic and Tank but am lost in comparing. Should I after the form have defined arrays? Such as $Medtronic = "[1],[2]" , "[1],[3]" , "[1],[4]" , Such as $Tank = "[2],[2]" , "[2],[3]" , "[2],[4]" , But how do I compare each of these results? I understand a if, else, else if but how to apply this? End result should be like this: You have selected Medtronic VS Tank: Medtronic Stat1 is 8 weaker thank Tank Medtronic stat2 is 10 stronger thank Tank Medtronic stat3 is 6 stronger thank Tank ..... It is the process of comparing a user selected row from a drop down to another row that has me confused. Any help would be greatly appreciated. Thank you heaps Edited May 12, 2014 by Check202 Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 12, 2014 Share Posted May 12, 2014 (edited) This should work for you. <?php $mediatronic = "12 20 40"; $tank = "20 10 34"; $number = -1; $m_array = array(); $t_array = array(); $m_array = explode(" ", $mediatronic); $t_array = explode(" ", $tank); echo "<b> You have selected Medtronic VS Tank: </b><br />"; foreach ($m_array as $m_value) { ++$number; $show_number = $number + 1; if ($m_value < $t_array[$number]) { $amount = $t_array[$number] - $m_value; echo "Medtronic Stat" . $show_number . " is ". $amount . " weaker than Tank <br />"; } elseif ($m_value > $t_array[$number]) { $amount = $m_value - $t_array[$number]; echo "Medtronic Stat" . $show_number . " is ". $amount . " stronger than Tank <br />"; } elseif ($m_value == $t_array[$number]) { echo "Medtronic Stat" . $show_number . " is equal to Tank <br />"; } else { echo "Unable to compare. <br />"; } } ?> returns: You have selected Medtronic VS Tank:Medtronic Stat1 is 8 weaker than TankMedtronic Stat2 is 10 stronger than TankMedtronic Stat3 is 6 stronger than Tank Edited May 12, 2014 by QuickOldCar 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.