Jump to content
MakeWebGames

Help! Need help!


Samurai Legend

Recommended Posts

Hello all, this here is my hire spy modification, however I am getting an error?

 

<?php

require('globals.php');

///Configuration 		
$item           = 0; //Item ID required to be obtained before performing a hire ninja.			
$prohibited     = array(1); //Add player IDs to this array who you want to be protected from hire ninja.
$prohibited_npc = true; //Set this to true to block NPC's from being spied on.
// End

if ($ir['donatordays'] <= 0) {
			error('This is a donator only option.');
}
$q1 = $db->query("SELECT * FROM `inventory` WHERE `inv_userid`= {$ir['userid']} and `inv_itemid` = $item");
if ($db->num_rows($q1) < 1) {
			error('You need to get in contact with a ninja.<br/>To get in contact with one, go buy a ninja card.');
}
if ($ir['jail'] > 0 || $ir['hospital'] > 0) {
			error('You can not hire a ninja on someone when your in jail or hospital.');
}
$_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';

$_POST['ID'] = (isset($_POST['ID']) && is_numeric($_POST['ID'])) ? abs(intval($_POST['ID'])) : '';

if ($_POST['ID']) {
			$q = $db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_POST['ID']}");
			$r = $db->fetch_assoc($q);
			if (in_array($_POST['ID'], $prohibited)) {
							error('The ninja never came back!<br />It was rumoured he was attacked by ' . $r['username'] . ' and pushed off a cliff.');
			}
			if (in_array($in, $prohibited)) {
							error('You cannot spy on this player.');
			}
			if ($r['fedjail']) {
							error('You cannot spy on people in federal jail.');
			}
			if ($in == $userid) {
							error('You cannot spy on yourself!');
			}
			$payment = $r['level'] * 100;
			if ($ir['money'] < $payment) {
							error("You need " . money_formatter($payment) . " to hire a ninja on this member.");
			} else {
							$payment = $r['level'] * 100;
							$db->query("UPDATE `users` SET `money` = `money` - '$payment' WHERE `userid` = '$userid'");
							$exp = (int) ($r['exp'] / (($r['level'] + 1) * ($r['level'] + 1) * ($r['level'] + 1) * 2) * 100);
							$ts  = $r['strength'] + $r['agility'] + $r['guard'] + $r['labour'] + $r['IQ'];
?>
<hr width='75%'>You have hired a ninja to get information on <b><?php
							echo format($r['username']);
?></b> at the cost of <?php
							echo money_formatter($payment);
?>. Here is the information retrieved:<hr width='75%'>
<h3><u>Statistics</u></h3>
<table cellspacing='1' border='0' cellpadding='1' class='table' width='75%'>
<tr><th colspan='2' class='h'><b>Stats Info</b></td></tr>
<tr>
<td>Strength: <?php
							echo format($r['strength']);
?></td>
<td>Agility: <?php
							echo format($r['agility']);
?></td>
</tr>
<tr>
<td>Guard: <?php
							echo format($r['guard']);
?></td>
<td>Labour: <?php
							echo format($r['labour']);
?></td>
</tr>
<tr>
<td>IQ: <?php
							echo format($r['IQ']);
?></td>
<td>EXP: <?php
							echo format($exp);
?>%</td>
</tr>
<tr>
<td colspan='2'><font color = red><b>Total Stats:</b></font><?php
							echo format($ts);
?></td>
</tr></table><br />
   <h3><u>Equipped Items</u></h3>
<?php
							$q1 = $db->query("SELECT * FROM items WHERE itmid IN({$r['equip_primary']}, {$r['equip_secondary']}, {$r['equip_armor']})");
							while ($r1 = $db->fetch_assoc($q1)) {
											$equip[$r1['itmid']] = $r1;
							}
?><table width='75%' cellspacing='1' class='table'>
<tr>
<th>Primary Weapon</th>
<td>
<?php
							if ($equip[$r['equip_primary']]['itmid']) { 
											echo $equip[$r['equip_primary']]['itmname'] . " ?></td>
                     <td>
		         	echo $equip[$r['equip_primary']]['itmdesc']. "  
                               </td>


							} else {
?>
											None equipped.</td><td> </td>
<?php
							}

?>
				<tr>
<th>Secondary Weapon</th>
<td>
			<?php				if ($equip[$r['equip_secondary']]['itmid']) {
											echo $equip[$r['equip_secondary']]['itmname'] . " ?></td>
<td>
			<?php								echo $equip[$r['equip_secondary']]['itmdesc'] . " ?></td>

<?php
		} else {
											?> None equipped.</td><td> </td>
<?php
							}
?>
				<tr>
<th>Armor</th>
<td>
				<?php			if ($equip[$r['equip_armor']]['itmid']) {
											echo $equip[$r['equip_armor']]['itmname'] . " ?></td>
<td>
				<?php							echo $equip[$r['equip_armor']]['itmdesc'] . "
?></td><?php
							} else {
?> 
											 None equipped.</td><td> </td> 
<?php
							}
?>
				</tr></table><br /> 
				 <h3><u>Inventory</u></h3> 

<?php

							$inv = $db->query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_userid={$r['userid']}");
							if ($db->num_rows($inv) == 0) {
?>
											 <hr width='75%'>This person has no items!<hr width='75%'>

<?php
							} else {
?>
											<b>Inventory listed below.</b><br />
<hr width='75%'><table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Item</th><th>Sell Value</th><th>Total Sell Value</th></tr>

<?php

												while ($i = $db->fetch_assoc($inv)) {
?>
															 <tr><td><?php echo format($i['itmname']); 
															if ($i['inv_qty'] > 1) {
 ?>
																			 x<?php echo format($i['inv_qty']); ?>
<?php
															}

?>
														</td><td><?php echo money_formatter($i['itmsellprice']); ?></td><td>
															<?php echo money_formatter($i['itmsellprice'] * $i['inv_qty']); ?>
															</td></tr>
<?php
											}
?>
	</table><hr width='75%'><br /><hr width='50%'><a href='viewuser.php?u=<?php echo $_POST['ID']; ?>'>> Go Back</a><hr width='50%'>

<?php
							}
			}
} else {
			$q = $db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}");
			if (!$_GET['ID']) {
							error('No valid player ID to hire spy specified.');
			} else if (!$db->num_rows($q)) {
							error('This user does not exist.');
			} else if ($_GET['ID'] == $userid) {
							error('What is the point in hiring a ninja on yourself.');
			} else {
							$r       = $db->fetch_assoc($q);
							$payment = $r['level'] * 100;
?>
<hr width='100%'>You are hiring a ninja to spy on <b><?php format($r['username']); ?></b> at the cost of <?php echo money_formatter($payment); ?><hr width='100%'>
							if ($ir['money'] >= $payment) {
	?> <form action='hireninja.php' method='post'><input type='hidden' name='ID' value='<?php echo $_GET['ID']; ?>' /><input type='submit' value='Hire' /></form>

<?php
							} else {
											error('You don not have enough money!');
							}
			}
}
$h->endpage();
?>

 

Error:

PHP Parse error:  syntax error, unexpected '[', expecting ']' in /home/****/public_html/hireninja.php on line 100

Error Line:

echo $equip[$r['equip_primary']]['itmdesc']. "  

 

Please help!

Link to comment
Share on other sites

Post picture of shoe on head (one you've not sent before) holding a sign with the word "sniko" on it. Because Jigsaw says he/she will use it, same applies. As soon as my demands are met, I'll fix.

You have 5 hours.

:D

Sounds like a ransom demand. xD

Edited by Script47
Link to comment
Share on other sites

Demands were not met. Shame. It's a super easy fix, too.

[MENTION=70383]Tangled[/MENTION] - I'll PM you the fix, as you met the demands :)

Message sent to you, please confirm :D

 

Check for semicolons on your echo statements. You are using the echo command multiple times without a semicolon.

~G7470

It's not entirely that. The code is super bugged.

Edited by sniko
Link to comment
Share on other sites

Code is super bugged, I have fixed all parse errors:

 

<?php

require('globals.php');

///Configuration        
$item           = 0; //Item ID required to be obtained before performing a hire ninja.          
$prohibited     = array(1); //Add player IDs to this array who you want to be protected from hire ninja.
$prohibited_npc = true; //Set this to true to block NPC's from being spied on.
// End

if ($ir['donatordays'] <= 0) {
               error('This is a donator only option.');
}
$q1 = $db->query("SELECT * FROM `inventory` WHERE `inv_userid`= {$ir['userid']} and `inv_itemid` = $item");
if ($db->num_rows($q1) < 1) {
               error('You need to get in contact with a ninja.To get in contact with one, go buy a ninja card.');
}
if ($ir['jail'] > 0 || $ir['hospital'] > 0) {
               error('You can not hire a ninja on someone when your in jail or hospital.');
}
$_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';

$_POST['ID'] = (isset($_POST['ID']) && is_numeric($_POST['ID'])) ? abs(intval($_POST['ID'])) : '';

if ($_POST['ID']) {
               $q = $db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_POST['ID']}");
               $r = $db->fetch_assoc($q);
               if (in_array($_POST['ID'], $prohibited)) {
                               error('The ninja never came back!It was rumoured he was attacked by ' . $r['username'] . ' and pushed off a cliff.');
               }
               if (in_array($in, $prohibited)) {
                               error('You cannot spy on this player.');
               }
               if ($r['fedjail']) {
                               error('You cannot spy on people in federal jail.');
               }
               if ($in == $userid) {
                               error('You cannot spy on yourself!');
               }
               $payment = $r['level'] * 100;
               if ($ir['money'] < $payment) {
                               error("You need " . money_formatter($payment) . " to hire a ninja on this member.");
               } else {
                               $payment = $r['level'] * 100;
                               $db->query("UPDATE `users` SET `money` = `money` - '$payment' WHERE `userid` = '$userid'");
                               $exp = (int) ($r['exp'] / (($r['level'] + 1) * ($r['level'] + 1) * ($r['level'] + 1) * 2) * 100);
                               $ts  = $r['strength'] + $r['agility'] + $r['guard'] + $r['labour'] + $r['IQ'];
?>
<hr width='75%'>You have hired a ninja to get information on <b><?php
                               echo format($r['username']);
?></b> at the cost of <?php
                               echo money_formatter($payment);
?>. Here is the information retrieved:<hr width='75%'>
   <h3><u>Statistics</u></h3>
   <table cellspacing='1' border='0' cellpadding='1' class='table' width='75%'>
   <tr><th colspan='2' class='h'><b>Stats Info</b></td></tr>
   <tr>
   <td>Strength: <?php
                               echo format($r['strength']);
?></td>
   <td>Agility: <?php
                               echo format($r['agility']);
?></td>
   </tr>
   <tr>
   <td>Guard: <?php
                               echo format($r['guard']);
?></td>
   <td>Labour: <?php
                               echo format($r['labour']);
?></td>
   </tr>
   <tr>
   <td>IQ: <?php
                               echo format($r['IQ']);
?></td>
   <td>EXP: <?php
                               echo format($exp);
?>%</td>
   </tr>
   <tr>
   <td colspan='2'><font color = red><b>Total Stats:</b></font><?php
                               echo format($ts);
?></td>
   </tr></table>
   <h3><u>Equipped Items</u></h3>
<?php
                               $q1 = $db->query("SELECT * FROM items WHERE itmid IN({$r['equip_primary']}, {$r['equip_secondary']}, {$r['equip_armor']})");
                               while ($r1 = $db->fetch_assoc($q1)) {
                                               $equip[$r1['itmid']] = $r1;
                               }
?><table width='75%' cellspacing='1' class='table'>
   <tr>
   <th>Primary Weapon</th>
   <td>
<?php
                               if ($equip[$r['equip_primary']]['itmid']) { 
                                               echo $equip[$r['equip_primary']]['itmname']; ?></td>
                        <td>
                       <?php echo $equip[$r['equip_primary']]['itmdesc']; ?>
                                  </td>

 <?php
                               } else {
?>
                                               None equipped.</td><td> </td>
<?php
                               }

?>
                   <tr>
   <th>Secondary Weapon</th>
   <td>
               <?php                if ($equip[$r['equip_secondary']]['itmid']) {
                                               echo $equip[$r['equip_secondary']]['itmname']; ?></td>
   <td>
               <?php                                echo $equip[$r['equip_secondary']]['itmdesc']; ?></td>

<?php
           } else {
                                               ?> None equipped.</td><td> </td>
<?php
                               }
?>
                   <tr>
   <th>Armor</th>
   <td>
                   <?php            if ($equip[$r['equip_armor']]['itmid']) {
                                               echo $equip[$r['equip_armor']]['itmname']; ?></td>
   <td>
                   <?php                            echo $equip[$r['equip_armor']]['itmdesc'];
   ?></td><?php
                               } else {
?> 
                                                None equipped.</td><td> </td> 
<?php
                               }
?>
                   </tr></table> 
                    <h3><u>Inventory</u></h3> 

<?php

                               $inv = $db->query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_userid={$r['userid']}");
                               if ($db->num_rows($inv) == 0) {
?>
                                                <hr width='75%'>This person has no items!<hr width='75%'>

<?php
                               } else {
?>
                                               <b>Inventory listed below.</b>
   <hr width='75%'><table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Item</th><th>Sell Value</th><th>Total Sell Value</th></tr>

<?php

                                               while ($i = $db->fetch_assoc($inv)) {
?>
                                                                <tr><td><?php echo format($i['itmname']); 
                                                               if ($i['inv_qty'] > 1) {
 ?>
                                                                                x<?php echo format($i['inv_qty']); ?>
<?php
                                                               }

?>
                                                           </td><td><?php echo money_formatter($i['itmsellprice']); ?></td><td>
                                                               <?php echo money_formatter($i['itmsellprice'] * $i['inv_qty']); ?>
                                                               </td></tr>
<?php
                                               }
?>
       </table><hr width='75%'><hr width='50%'><a href='viewuser.php?u=<?php echo $_POST['ID']; ?>'>> Go Back</a><hr width='50%'>

<?php
                               }
               }
} else {
               $q = $db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}");
               if (!$_GET['ID']) {
                               error('No valid player ID to hire spy specified.');
               } else if (!$db->num_rows($q)) {
                               error('This user does not exist.');
               } else if ($_GET['ID'] == $userid) {
                               error('What is the point in hiring a ninja on yourself.');
               } else {
                               $r       = $db->fetch_assoc($q);
                               $payment = $r['level'] * 100;
?>
<hr width='100%'>You are hiring a ninja to spy on <b><?php format($r['username']); ?></b> at the cost of <?php echo money_formatter($payment); ?><hr width='100%'>
                              <?php

						   if ($ir['money'] >= $payment) {
       ?> <form action='hireninja.php' method='post'><input type='hidden' name='ID' value='<?php echo $_GET['ID']; ?>' /><input type='submit' value='Hire' /></form>

<?php
                               } else {
                                               error('You don not have enough money!');
                               }
               }
}
$h->endpage();
?>

 

It's not even worth asking some unknown person for some random image for 2 minutes of your time.

Link to comment
Share on other sites

Too many open and closing php tags not necessary, just because you have html in your code does not mean you have to end php tags than write them in then start php again, include the html into the php tags by using echo and making sure you also end the echo statement, some of your echo statements were not closed. why you got the error. Just badly coded all together with all the open and closing of php in my opinion.

Link to comment
Share on other sites

Thanks all for helping! However I am trying something new and soon to release to the community.

I need to join all these queries as one.

 

$ql = $db->query("SELECT `level`, `username`, `equip_primary`, `equip_secondary`, `equip_armor`, `equip_shield`, `money`, `coins`,           `rating`, `bankmoney`, `cybermoney`, `steps`, `user_level`, `crimexp` FROM `users` WHERE `userid` = '{$_GET['ID']}'");
   $r = $db->fetch_row($sql);

$sta = sprintf('SELECT `strength`, `agility`, `guard`, `labour`, `IQ` FROM userstats WHERE userid = %u', $_GET['ID']);
$sta = $db->query($sta);
$stats=$db->fetch_row($sta);
$we = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_primary']);
$we = $db->query($we);
$pri=$db->fetch_row($we);
$we1 = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_secondary']);
$we1 = $db->query($we1);
$sey=$db->fetch_row($we1);
$we2 = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_armor']);
$we2 = $db->query($we2);
$arm=$db->fetch_row($we2);
Link to comment
Share on other sites

Thanks all for helping! However I am trying something new and soon to release to the community.

I need to join all these queries as one.

 

$ql = $db->query("SELECT `level`, `username`, `equip_primary`, `equip_secondary`, `equip_armor`, `equip_shield`, `money`, `coins`,           `rating`, `bankmoney`, `cybermoney`, `steps`, `user_level`, `crimexp` FROM `users` WHERE `userid` = '{$_GET['ID']}'");
   $r = $db->fetch_row($sql);

$sta = sprintf('SELECT `strength`, `agility`, `guard`, `labour`, `IQ` FROM userstats WHERE userid = %u', $_GET['ID']);
$sta = $db->query($sta);
$stats=$db->fetch_row($sta);
$we = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_primary']);
$we = $db->query($we);
$pri=$db->fetch_row($we);
$we1 = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_secondary']);
$we1 = $db->query($we1);
$sey=$db->fetch_row($we1);
$we2 = sprintf('SELECT `itmname` FROM items WHERE itmid = %u', $r['equip_armor']);
$we2 = $db->query($we2);
$arm=$db->fetch_row($we2);

If you want to have the exact item name for each item equipped, it will be a little tricky to do, but this is what I came up with:

 

$query = $db->query("SELECT `itmname`, `itmid` FROM `items` WHERE `itmid` IN (".$r['equip_primary'].", ".$r['equip_secondary'].", ".$r['equip_armor'].")");
while($getresults = $db->fetch_assoc($query))
{
switch $getresults['itmid']
{
	case $r['equip_primary']:
		$priName = $getresults['itmname'];
		break;
	case $r['equip_secondary']:
		$secName = $getresults['itmname'];
		break;
	default:
		$armName = $getresults['itmname'];
		break;
}
}
Link to comment
Share on other sites

If you want to have the exact item name for each item equipped, it will be a little tricky to do, but this is what I came up with:

 

$query = $db->query("SELECT `itmname`, `itmid` FROM `items` WHERE `itmid` IN (".$r['equip_primary'].", ".$r['equip_secondary'].", ".$r['equip_armor'].")");
while($getresults = $db->fetch_assoc($query))
{
switch $getresults['itmid']
{
	case $r['equip_primary']:
		$priName = $getresults['itmname'];
		break;
	case $r['equip_secondary']:
		$secName = $getresults['itmname'];
		break;
	default:
		$armName = $getresults['itmname'];
		break;
}
}

 

Thanks so much! How would I echo the statements? This is something new i just learnt! Thanks again so much, I just need to know how I am going to find out how to echo the statements :)

Link to comment
Share on other sites

Below are the echo statements for each item name using the code I posted:

 

echo $priName; // Will display equipped primary weapon name
echo $secName; // Will display equipped secondary weapon name
echo $armName; // Will display equipped armor name 

 

Take those and change them as needed in order to format them as desired.

~G7470

Link to comment
Share on other sites

Thank you so much again!

 

So if there was no one equiping anything on, so the variables be 0. How would I say none on it

 

while($getresults = $db->fetch_row($query))
{
   switch (!$getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = $getresults['itmname'];
           break;
       case $r['equip_secondary']:
           $secName = $getresults['itmname'];
           break;
       default:
           $armName = $getresults['itmname'];
           break;
   }
   else
   {
      switch ($getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = None;
           break;
       case $r['equip_secondary']:
           $secName = None;
           break;
       default:
           $armName = None;
           break;
   }
}

 

This seems to be not working...

Link to comment
Share on other sites

Following the code that you just wrote:

 

while($getresults = $db->fetch_row($query))
{
   switch (!$getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = $getresults['itmname'];
           break;
       case $r['equip_secondary']:
           $secName = $getresults['itmname'];
           break;
       default:
           $armName = $getresults['itmname'];
           break;
   }
   else
   {
      switch ($getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = None;
           break;
       case $r['equip_secondary']:
           $secName = None;
           break;
       default:
           $armName = None;
           break;
   }
}

 

I can see what you are trying to do, but that method simply will not work (as you have already experienced). You are basically trying to compare results that do not even exist in the first switch statement, and then trying to do an "else" statement with a switch, which is syntactically incorrect.

This is how I would do it:

 

while($getresults = $db->fetch_row($query))
{
   switch ($getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = $getresults['itmname'];
           break;
       case $r['equip_secondary']:
           $secName = $getresults['itmname'];
           break;
       default:
           $armName = $getresults['itmname'];
           break;
   }
}
if(!isset($priName))
{
  $priName = "None Equipped";
}
if(!isset($secName))
{
  $secName = "None Equipped";
}
if(!isset($armName))
{
  $armName = "None Equipped";
}

 

Assuming you have NO items with an ID of 0 (which you really shouldn't), then this should work for you.

Read through the code that I just wrote and let me know if you have any questions about how it works.

~G7470

Edited by G7470
Link to comment
Share on other sites

I found another script, so I decided to fix it up, thanks to G7470 for helping me out.

 

<?php

require('globals.php');

$_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';  
$_GET['PAID'] = (isset($_GET['PAID']) && is_numeric($_GET['PAID'])) ? abs(intval($_GET['PAID'])) : '';

   if(!$ir['donatordays'])
   {
   error('Only donators can access this area.');
   }
$sql = $db->query("SELECT `level`, `username`, `equip_primary`, `equip_secondary`, `equip_armor`, `equip_shield`, `money`, `coins`,           `rating`, `bankmoney`, `cybermoney`, `steps`, `user_level`, `crimexp` FROM `users` WHERE `userid` = '{$_GET['ID']}'");
   $r = $db->fetch_row($sql);


   if($_GET['ID'] == $userid)
   {
   error('Why would you wanna spy on yourself?');
   }
   if($_GET['ID'] && $_GET['PAID'])
   {
   $cost = $r['level'] * 100;
   if($_GET['PAID'] != $cost)
   {
   error('Quit trying to abuse bugs.');
   }
   if($_GET['PAID'] > $ir['money'])
   {
   error('You do not have enough money to spy on '.$r['username'].'.');
   }


   $rand = rand(1,15);
   if($rand == 1)
   {
   $db->query("UPDATE `users` SET `money` = `money` - '{$_GET['PAID']}' WHERE `userid` = '{$ir['userid']}'");
   action("The ninja you have hired has been caught.<br/>Your name may have been mentioned.");
   event_add($_GET['ID'],"<a href='viewuser.php?u={$ir['userid']}'>{$ir['username']}</a> tried to hire a ninja on you but failed.");
   } 
   else
   {
   $db->query("UPDATE `users` SET `money` = `money` - '{$_GET['PAID']}' WHERE `userid` = '{$ir['userid']}'");
   if($r['user_level'] == 2)
   {
   action("The ninja never came back. It was rumoured he was attacked by {$r['username']} and pushed off a cliff.");
   exit($h->endpage());
   }



$sta = $db->query("SELECT `strength`, `agility`, `guard`, `labour`, `IQ` FROM `userstats` WHERE `userid` = '{$_GET['ID']}'");
$stats = $db->fetch_row($sta);



$query = $db->query("SELECT `itmname`, `itmid` FROM `items` WHERE `itmid` IN (".$r['equip_primary'].", ".$r['equip_secondary'].", ".$r['equip_armor'].", ".$r['equip_shield'].")");

while($getresults = $db->fetch_row($query))
{
   switch ($getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = $getresults['itmname'];
           break;
       case $r['equip_secondary']:
           $secName = $getresults['itmname'];
           break;
       case $r['equip_shield']:
           $shName = $getresults['itmname'];
           break;
       default:
           $armName = $getresults['itmname'];
           break;
   }

}
if(!isset($priName))
{
  $priName = "None Equipped";
}
if(!isset($secName))
{
  $secName = "None Equipped";
}
if(!isset($armName))
{
  $armName = "None Equipped";
}
if(!isset($shName))
{
  $shName = "None Equipped";
}


if ($stats['strength'] > $ir['strength']) {
   $stren = "<font color='red'>Weaker</font>";
} elseif ($stats['strength'] == $ir['strength']) {
   $stren = "<font color='blue'>Equal</font>";
} else {
   $stren = "<font color='green'>Stronger</font>";
}
if ($stats['agility'] > $ir['agility']) {
   $agility = "<font color='red'>Weaker</font>";
} elseif ($stats['agility'] == $ir['agility']) {
   $agility = "<font color='blue'>Equal</font>";
} else {
   $agility = "<font color='green'>Stronger</font>";
}
if ($stats['guard'] > $ir['guard']) {
   $guard = "<font color='red'>Weaker</font>";
} elseif ($stats['guard'] == $ir['guard']) {
   $guard = "<font color='blue'>Equal</font>";
} else {
   $guard = "<font color='green'>Stronger</font>";
}
if ($stats['labour'] > $ir['labour']) {
   $labour = "<font color='red'>Weaker</font>";
} else if ($stats['labour'] == $ir['labour']) {
   $labour = "<font color='blue'>Equal</font>";
} else {
   $labour = "<font color='green'>Stronger</font>";
}
if ($stats['IQ'] > $ir['IQ']) {
   $IQ = "<font color='red'>Weaker</font>";
} else if ($stats['IQ'] == $ir['IQ']) {
   $IQ = "<font color='blue'>Equal</font>";
} else {
   $IQ = "<font color='green'>Stronger</font>";
}

echo"<hr width='75%'>You have hired a ninja to get information on <b>{$r['username']}</b> at the cost of ". money_formatter($_GET['PAID']) ."
<br />Here is the information retrieved:<hr width='75%'>
   <h3><u>Statistics</u></h3>";



 echo "<hr/><table width = '90%' cellspacing = '1' class='table'><tr style='background:gray'>
       <tr><th>Primary</th>
           <th>Secondary</th>
           <th>Armor</th>
           <th>Shield</th>
       </tr>
       <tr><td>$priName</td><td>$secName</td><td>$armName</td><td>$shName</td></tr>
       </table>";



echo"<hr/>
       <table width='90%' cellspacing='1' class='table'> 
       <tr style='background:gray'>
       <tr>
       <th>Stats</th><th>Your Stats</th><th>Stats</th><th>Their Stats</th><th>Result</th>
       </tr>
       <tr>
       <td>Strength:</td><td> {$ir['strength']}</td><td>Strength:</td><td>{$stats['strength']}</td><td><center><b>$stren</b></center></td>
       </tr>
       <tr>
       <td>Agility:</td><td>{$ir['agility']}</td><td>Agility:</td><td>{$stats['agility']}</td><td><center><b>$agility</b></center></td>
       </tr>
       <tr>
       <td>Guard:</td><td>{$ir['guard']}</td><td>Guard:</td><td> {$stats['guard']}</td><td><center><b>$guard</b></center></td>
       </tr>
       <tr>
       <td>Labour:</td><td>{$ir['labour']}</td><td>Labour:</td><td>{$stats['labour']}</td><td><center><b>$labour</b></center></td>
       </tr>
       <tr>
       <td>IQ:</td><td> {$ir['IQ']}</td><td>IQ:</td><td> {$stats['IQ']}</td><td><center><b>$IQ</b></center></td>
       </tr>";

        echo"
       <table width='90%' cellspacing='1' class='table'> 
       <tr style='background:gray'>
       <tr>
       <td><center><a href='attack.php?ID={$_GET['ID']}'><b>Attack?</b></a></center></td>
       </tr>
       </table><hr />
       <table width='90%' cellspacing='1' class='table'> 
       <tr style='background:gray'>
       <tr>
       <th>Currency</th><th>Amount<th>Misc</th>
       </tr>
       <tr>
       <td>Money:</td><td>".money_formatter($r['money'])."</td>
       <td>Rating: {$r['rating']}</td>
       </tr>
       <tr>
       <td>Coins:</td><td>{$r['coins']}</td>
       <td>Crime EXP: {$r['crimexp']}</td>
       </tr>
       <tr>
       <td>Street Steps:</td><td> {$r['steps']}</td>
       <td>Level: {$r['level']}</td>
       </tr>
       </table>";

       echo" 
       <hr />
       <table width='90%' cellspacing='1' class='table'> 
       <tr style='background:gray'>
       <tr>
       <th>Name</th><th>Description</th><th>Amount</th></tr>";

$z = $db->query("SELECT `inv_itemid`, `inv_qty` FROM `inventory` WHERE `inv_userid` = {$_GET['ID']} ORDER BY inv_itemid DESC");

if ($db->num_rows($z) == 0) {
echo"<th colspan='3'>This person has no items!</th>";
}  
while($e=$db->fetch_row($z))
{
$t = $db->query("SELECT `itmname`, `itmdesc` FROM `items` WHERE `itmid` = {$e['inv_itemid']}");
$itm=$db->fetch_row($t);
echo "
<tr>
<td>{$itm['itmname']}</td>
<td>{$itm['itmdesc']}</td>
<td>" . money_formatter($e['inv_qty']) . "</td></tr>";
}

echo "</table><hr/><br/><hr width='75%'>><a href='viewuser.php?u={$_GET['ID']}'>Go Back</a><hr width='75%'>";
}
}
else if($_GET['ID'])
{
$cost = $r['level'] * 100;
echo "<hr/><b>You are hiring a ninja on {$r['username']}</b>It will cost you " . money_formatter($cost) . " for the ninja expenses.<br />But be warned spying is not always 100% successful.
<form action='hireninja.php' method='get'>
<input type='hidden' name='ID' value='{$_GET['ID']}' />
<input type='hidden' name='PAID' value='$cost' />
<hr/>
<input type='submit' value='Hire Ninja'/></form><hr/>$goback<hr/>";
}
else
{
error('System error!');
}
$h->endpage();
Link to comment
Share on other sites

This is how I would do it:

 

while($getresults = $db->fetch_row($query))
{
   switch ($getresults['itmid'])
   {
       case $r['equip_primary']:
           $priName = $getresults['itmname'];
           break;
       case $r['equip_secondary']:
           $secName = $getresults['itmname'];
           break;
       default:
           $armName = $getresults['itmname'];
           break;
   }
}
if(!isset($priName))
{
  $priName = "None Equipped";
}
if(!isset($secName))
{
  $secName = "None Equipped";
}
if(!isset($armName))
{
  $armName = "None Equipped";
}

 

~G7470

You don't actually need all those isset's..

 

$priName = 'None Equipped';
$secName = 'None Equipped';
$armName = 'None Equipped';

$query = $db->query("SELECT `itmname`, `itmid` FROM `items` WHERE `itmid` IN (".$r['equip_primary'].", ".$r['equip_secondary'].", ".$r['equip_armor'].")");
while($getresults = $db->fetch_row($query)) {

switch($getresults['itmid']) {

	case $r['equip_primary']:
		$priName = $getresults['itmname'];
		break;

	case $r['equip_secondary']:
		$secName = $getresults['itmname'];
		break;

	case $r['equip_armor']:
		$armName = $getresults['itmname'];
		break;

}

}
Link to comment
Share on other sites

You don't actually need all those isset's..

 

$priName = 'None Equipped';
$secName = 'None Equipped';
$armName = 'None Equipped';

$query = $db->query("SELECT `itmname`, `itmid` FROM `items` WHERE `itmid` IN (".$r['equip_primary'].", ".$r['equip_secondary'].", ".$r['equip_armor'].")");
while($getresults = $db->fetch_row($query)) {

switch($getresults['itmid']) {

	case $r['equip_primary']:
		$priName = $getresults['itmname'];
		break;

	case $r['equip_secondary']:
		$secName = $getresults['itmname'];
		break;

	case $r['equip_armor']:
		$armName = $getresults['itmname'];
		break;

}

}

It all depends on how you would want to structure your code. I made that code on-the-fly, so I really did not take the time to analyze the "least code" method. Regardless, both methods (what I did VS what you did) have their pros and cons. It's all personal preference.

~G7470

Link to comment
Share on other sites

It all depends on how you would want to structure your code. I made that code on-the-fly, so I really did not take the time to analyze the "least code" method. Regardless, both methods (what I did VS what you did) have their pros and cons. It's all personal preference.

~G7470

Apart from more processing power to check for each isset. They essentially do the same. But regardless if this was on-the-fly. I was providing a tip, and not necessarily telling you to code like that. But it's best to start practicing Rule of least power.

Also, it's not about "least code" method either, but the simple KISS (Keep it simple stupid) principle.

Creating "on-the-fly" simple, logical code, does not take a lot of brain power :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...