Dethman Posted July 13, 2008 Share Posted July 13, 2008 Hello all, I am working on a call system for another players stats on one of my game for some reason its not displaying the info that I need. Here is the function (Its Massive Dont know if Im allowed to use a function this big ) function getSpellStatus($userID){ //Run the query to select all the users weapons! $q=mysql_query("select * from `user_weapons` where `userid`='$userID' AND `quantity` > 0") or die(mysql_error()); //Before the loop //We should declare the vweaponFullStrength and weaponStrength $weaponFullStrength = 0; $weaponStrength = 0; while($row = mysql_fetch_array($q)){ //THIS LOOPS THROUGH ALL THE RECORDS IN THE DATABASE. SO IT JUST DOESN'T GRAB THE FIRST, IT"LL GRAB ALL OF THEM! //Now that we are looping through all the rows we need to get the default data for the weapon //But first, lets set some variables $id = $row['weaponID']; $strength = $row['strength']; $quantity = $row['quantity']; //Got the variables... //Now we can get the default data for the weapon with the id $id //This query grabs the weapon that has the matching id from race_weapons $q2 = mysql_query("select * from `race_weapons` where `weaponID`='$id'") or die(mysql_error()); //This grabs all the information for the weapon and puts it into the $rack variable. $rack=mysql_fetch_array($q2); //Lets set some more variables... $defaultStrength = $rack['weaponDefaultStrength']; //You may not need these but we'll set them anyway... $name = $rack['weaponName']; $attack = $rack['weaponAttack']; //Now lets get how much strength we have combined!!!! //We use the += to add to the current variable... $weaponFullStrength += ($defaultStrength*$quantity); $weaponStrength += ($strength*$quantity); } //CLOSE THE WHILE LOOP //Now we can work out the percentage, now that the loop is over. if($weaponFullStrength == 0 || $weaponStrength == 0){ $page="<tr> <td align=left><font color=''><b>Spell Status</b></font></td> <td align=right><font color=''>0%</font></td> </tr>"; }else{ $damangePercent = (ceil($weaponFullStrength / $weaponStrength) * 100); //this gives us the damage percentage $capablePower = 100 - $damagePercent; $page=" <tr> <td align=left><font color=''><b>Spell Status</b></font></td> <td align=right><font color=''>{$capablePower}%</font></td> </tr> "; } return $page; } function getStats($id){ $q=("SELECT * FROM `user_users` WHERE `userid`='$id'"); $v=mysql_query($q); $player2=mysql_fetch_array($v); $username=$player2['username']; $rank=$player2['overallRank']; $realm=$player2['tag']; $AEP=$player2['PPT']; $coid=$player2['commander']; $rid=$player2['raceID']; $l=$player2['loyalty']; $q2=("SELECT * FROM `user_users` WHERE `userid`='$coid'"); $v2=mysql_query($q2); $co=mysql_fetch_array($v2); if($co['username']==""){ $commander="None"; } else{ $commander=$co['username']; } $CovertStrength1 = $player['covertLVL']*$player['covertTroops']; $finalCovStrength = $CovertStrength1*1.20; $cov2 = $player2['covertLVL']*$player2['covertTroops']; if($cov2 <= $finalCovStrength){ $treasury=$player2['credits']; $total_army=($player2['attackTroops']+$player2['defenseTroops']+$player['untrainedTroops']+$player2['covertTroops']+$player2['atkTroops']+$player2['defTroops']+$player2['farmer']+$player2['psicreator']); $trained_army=($player2['attackTroops']+$player2['defenseTroops']+$player2['covertTroops']+$player2['atkTroops']+$player2['defTroops']+$player2['farmer']+$player2['psicreator']); $def_rate=getSpellStatus($id); } else{ $treasury="??????"; } if ($rid==1){ $race="Fire"; } elseif ($rid==2){ $race="Water"; } elseif ($rid==3){ $race="Earth"; } elseif ($rid==4){ $race="Air"; } if($l==0){ $loyalty="Rogue Scum"; } elseif($l==1){ $loyalty="Chaotic"; } elseif($l==2){ $loyalty="Lawful"; } elseif($l==3){ $loyalty="Healing"; } elseif($l==4){ $loyalty="Deadly"; } if($AEP==1){ $AEP_1="{Under Ancient's Enchantment Protection}"; } else{ $AEP_1=""; } $q3="SELECT * FROM `user_users` WHERE `commander` = '$id' ORDER BY `overallRank` ASC"; $v3=mysql_query($q3); $count=mysql_num_rows($v3); if($count<1){ $apprentice_page="<TD colspan=3><center>No Additional Apprentices</center></TD> "; }else{ while($row=mysql_fetch_array($v3)){ if($row['raceID']==1){ $app_race="Fire"; } elseif($row['raceID']==2){ $app_race="Water"; } elseif($row['raceID']==3){ $app_race="Earth"; } elseif($row['raceID']==4){ $app_race="Air"; } $apprentice_page.=" <tr> <td align='left'><a href='stats.php?id=".$row['userid']."'>".$row['username']."</a></td> <td align='left'>".$app_race."</td> <td align='right'>".$row['overallRank']."</td> </tr>"; } $sql = "SELECT * FROM `plan` WHERE `userid` = '$id' ORDER BY `Plan_size` DESC"; $result = mysql_query($sql) or die('Query failed.' . mysql_error()); for ($i = 0; $i < mysql_num_rows($result);$i++) { $plan_Name = mysql_result($result,$i,"plan_name"); $plan_Size = mysql_result($result,$i,"plan_size"); $plan_Type = mysql_result($result,$i,"plan_attribute"); $plan_Prod = mysql_result($result,$i,"plan_product"); $plan_Defe = mysql_result($result,$i,"plan_defense"); if ($plan_Type == 1) { $attribute = number_format(ceil(125000 * $plan_Prod * pow(3.5,$plan_Size))); $type = " Defence"; $defamt = number_format(300000 * $plan_Defe); } elseif ($plan_Type == 2) { $attribute = number_format(ceil(135000 * $plan_Prod * pow(3.5,$plan_Size))); $type = " Attack"; $defamt = number_format(300000 * $plan_Defe); } elseif ($plan_Type == 3) { $attribute = number_format(ceil(500000 * $plan_Prod * pow(1.85,$plan_Size))); $type = " Spy"; $defamt = number_format(300000 * $plan_Defe); } elseif ($plan_Type == 4) { $attribute = number_format(ceil(480000 * $plan_Prod * pow(1.3,$plan_Size))); $type = " Income"; $defamt = number_format(300000 * $plan_Defe); } elseif ($plan_Type == 5) { $attribute = number_format(ceil($plan_Prod * pow(1.1,$plan_Size))); $type = " Up"; $defamt = number_format(300000 * $plan_Defe); } switch ($plan_Size) { case 0: $Size = "Tiny"; break; case 1: $Size = "Very Small"; break; case 2: $Size = "Small"; break; case 3: $Size = "Normal"; break; case 4: $Size = "Large"; break; case 5: $Size = "Big"; break; case 6: $Size = "Massive"; break; case 7: $Size = "On verg of a blackhole"; break; } $ammout_plan=mysql_num_rows($result); if($ammout_plan <1){ $planet_stats="<TD colspan=3><center>No Additional Villages</center></TD> "; }else{ $planet_stats=" <TR> <TD align=left>".$plan_Name."</TD> <TD align=left>".$Size."</TD> <TD align=right>".$type."</TD> </TR> "; } return array($username,$realm,$treasury,$commander,$total_army,$trained_army,$def_rate,$race,$loyalty,$AEP_1,$apprentice_page,$planet_stats,$rank); } } } Here is the call function $p2id=$_GET['id']; list($username,$realm,$treasury,$commander,$total_army,$trained_army,$def_rate,$race,$loyalty,$AEP_1,$apprentice_page,$planet_stats,$race) = getStats($p2id); Link to comment https://forums.phpfreaks.com/topic/114496-solved-huge-function-help/ Share on other sites More sharing options...
Third_Degree Posted July 13, 2008 Share Posted July 13, 2008 well with that much code, the best thing to do is take off the function braces, slap an error_reporting( E_ALL ); at the top of the page and run the code, see what happens. Hopefully that can give you an idea of the problem. Link to comment https://forums.phpfreaks.com/topic/114496-solved-huge-function-help/#findComment-588771 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Well first you included the function above it as well. The one I helped you with last night which I am assuming isn't a problem... Now... If you have a closer look, your return is inside your for loop. Link to comment https://forums.phpfreaks.com/topic/114496-solved-huge-function-help/#findComment-588774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.