Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Automatically update <div> after another <div> update?

    Good morning!

    I'm looking to see if anyone could help me with a small project I'm working on. I am making a tracker for a game (Call of Duty: World at War) for my "clan" which allows members to record their statistics. I've implemented edit-in-place functionality on the page using jQuery and the jEditable plugin.

    Everything works perfectly apart from two statistics, the "Kill to Death Ratio" and "Win to Loss Ratio". The user can use the edit-in-place functionality to edit their "Kills", "Deaths", "Wins" and "Losses" without a page refresh, however I haven't a clue how to get the "Kill to Death Ratio" and "Win to Loss Ratio" to update at the same time.

    I think it's self explanatory that the "Kill to Death Ratio" and "Win to Loss Ratio" are calculated as Kill-Death Ratio = Kills / Deaths and Win-Loss Ratio = Wins / Losses.

    Here is my code for the page (I'm using Drupal so ignore the Drupal API etc):

    Code:
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://www.warhawkinfo.com/scripts/jquery.jeditable.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function()
    {
      $(".weapons_edit").editable("http://www.warhawkinfo.com/home/save-tracker-mp.php",
      { 
        	indicator	: "<img src='http://www.warhawkinfo.com/images/ajax-indicator.gif'>",
        	data	: "{'SVT-40':'SVT-40','Gewehr-43':'Gewehr-43','M1 Garand':'M1 Garand','STG-44':'STG-44','M1A1 Carbine':'M1A1 Carbine','Thompson':'Thompson','MP40':'MP40','Type 100':'Type 100','PPSH-41':'PPSH-41','Type 99':'Type 99','BAR':'BAR','DP-28':'DP-28','MG-42':'MG-42','FG-42':'FG-42','Browning M1919':'Browning M1919','Springfield':'Springfield','Arisaka':'Arisaka','Mosin-Nagant':'Mosin-Nagant','KAR-98K':'KAR-98K','PTRS-41':'PTRS-41','Trench Gun':'Trench Gun','Double-Barrelled Shotgun':'Double-Barrelled Shotgun','M1911 Bazooka':'M1911 Bazooka','Bouncing Betty':'Bouncing Betty','Satchel Charge':'Satchel Charge','Frag Grenade':'Frag Grenade','Sticky Grenade':'Sticky Grenade','Molotov Cocktail':'Molotov Cocktail','M2 Flamethrower':'M2 Flamethrower'}",
        	type	: "select",
        	tooltip	: "Click to edit the weapon...",
        	onblur	: "submit",
        	style	: "inherit"
      });
      $(".pistols_edit").editable("http://www.warhawkinfo.com/home/save-tracker-mp.php",
      { 
    	indicator	: "<img src='http://www.warhawkinfo.com/images/ajax-indicator.gif'>",
    	data	: "{'Colt M1911':'Colt M1911','Nambu':'Nambu','Walther P-38':'Walther P-38','Tokarev TT-33':'Tokarev-TT-33','Magnum .357':'Magnum.357'}",
    	type	: "select",
    	tooltip	: "Click to edit the pistol...",
    	onblur	: "submit",
    	style	: "inherit"
      });
      $(".prestige_edit").editable("http://www.warhawkinfo.com/home/save-tracker-mp.php",
      { 
    	indicator	: "<img src='http://www.warhawkinfo.com/images/ajax-indicator.gif'>",
    	data	: "{'Not Prestiged':'Not Prestiged','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'10'}",
    	type	: "select",
    	tooltip	: "Click to edit your prestige...",
    	onblur	: "submit",
    	style	: "inherit"
      });
      $(".rank_edit").editable("http://www.warhawkinfo.com/home/save-tracker-mp.php", { 
    	indicator	: "<img src='http://www.warhawkinfo.com/images/ajax-indicator.gif'>",
    	data	: "{'1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'10','11':'11','12':'12','13':'13','14':'14','15':'15','16':'16','17':'17','18':'18','19':'19','20':'20','21':'21','22':'22','23':'23','24':'24','25':'25','26':'26','27':'27','28':'28','29':'29','30':'30','31':'31','32':'32','33':'33','34':'34','35':'35','36':'36','37':'37','38':'38','39':'39','40':'40','41':'41','42':'42','43':'43','44':'44','45':'45','46':'46','47':'47','48':'48','49':'49','50':'50','51':'51','52':'52','53':'53','54':'54','55':'55','56':'56','57':'57','58':'58','59':'59','60':'60','61':'61','62':'62','63':'63','64':'64','65':'65'}",
    	type	: "select",
    	tooltip	: "Click to edit your rank...",
    	onblur	: "submit",
    	style	: "inherit"
      });
      $(".stat_edit").editable("http://www.warhawkinfo.com/home/save-tracker-mp.php",
      { 
    	indicator	: "<img src='http://www.warhawkinfo.com/images/ajax-indicator.gif'>",
    	tooltip	: "Click to edit this statistic...",
    	onblur	: "submit",
    	style	: "inherit"
      });
    });
    </script>
    
    <? if (user_is_logged_in()) {
    
    global $user;
    $me = user_load(array('uid' => $user->uid));
    $psn = $me->profile_psn;
    
    $sql_un = "username";
    $sql_pw = "password";
    $sql_db = "the-immortality_com_tracker-codwaw";
    mysql_connect("127.0.0.1", $sql_un, $sql_pw);
    mysql_select_db($sql_db) or die("Unable to connect to CoD-WaW Tracker database.");
    	
    if(!mysql_num_rows(mysql_query("SELECT psn FROM multiplayer WHERE uid = '$user->uid'")) > 0)
    {
    mysql_query("INSERT INTO multiplayer (uid,psn,prestige,rank,time_played_days,time_played_hours,world_ranking,kills,deaths,wins,losses,kill_streak,death_streak,win_streak,fav_weapon,lfav_weapon,fav_pistol,lfav_pistol,dog_kills,artillery_kills) VALUES ('$user->uid','$psn','0','1','0','0','0','1','1','1','1','0','0','0','Unknown','Unknown','Unknown','Unknown','0','0')");
    }
    
    ?>
    
    Welcome to your personal CoD:WaW Tracker <? echo $psn; ?>. This tool allows you to record and maintain various statistics of your CoD:WaW gaming such as what missions you have completed and what trophies you have attained. Your statistics can be edited at any time and all the data you provide will be used in your TB$ profile.
    <br><br>
    To better use this facility, we highly recommend you register to <a href="http://www.callofduty.com">www.callofduty.com</a> and link your stats so that your stats are as accurate as possible.
    <br>
    <br>
    <hr>
    <br>
    <div align="center" style="font-family: Arial Black; font-size: 24px; color: black">
    <b>Multiplayer Statistics</b>
    </div>
    <? $result = mysql_query("SELECT * FROM multiplayer WHERE uid = '$user->uid'");
    $mpstat = mysql_fetch_row($result); ?>
    <br>
    <table>
    	<tr>
    		<th>Prestige</th>
    			<td>
    			<div id="prestige" class="prestige_edit" style="display: inline">
    			<? echo ($mpstat[2] > 0) ? '<img src="/images/prestige_icons/prestige' . $mpstat[2] . '.png">' : 'Not Prestiged'; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Rank</th>
    			<td>
    			<div id="rank" class="rank_edit" style="display: inline">
    			<? echo $mpstat[3]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Time played</th>
    			<td>
    			<div id="time_played_days" class="click" style="display: inline">
    			<? echo $mpstat[4]; ?>
    			</div>
    			<div style="display: inline"> days, </div>
    			<div id="time_played_hours" class="click" style="display: inline">
    			<? echo $mpstat[5]; ?>
    			</div>
    			<div style="display: inline"> hours</div>
    			</td>
    	</tr><tr>
    		<th>World ranking (score)</th>
    			<td>
    			<div id="world_ranking" class="click" style="display: inline"><? echo $mpstat[6]; ?></div>
    			</td>
    	</tr><tr>
    		<th>Kills</th>
    			<td>
    			<div id="kills" class="click" style="display: inline">
    			<? echo $mpstat[7]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Kills from Dogs</th>
    			<td>
    			<div id="dog_kills" class="click" style="display: inline">
    			<? echo $mpstat[18]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Kills from Artillery</th>
    			<td>
    			<div id="artillery_kills" class="click" style="display: inline">
    			<? echo $mpstat[19]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Deaths</th>
    			<td>
    			<div id="deaths" class="click" style="display: inline">
    			<? echo $mpstat[8]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Kill to Death Ratio</th>
    			<td>
    			<div id="kill_death_ratio" style="display: inline">
    			<? echo round($mpstat[7] / $mpstat[8], 2); ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Kill Streak</th>
    			<td>
    			<div id="kill_streak" class="click" style="display: inline">
    			<? echo $mpstat[11]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Death Streak</th>
    			<td>
    			<div id="death_streak" class="click" style="display: inline">
    			<? echo $mpstat[12]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Wins</th>
    			<td>
    			<div id="wins" class="click" style="display: inline">
    			<? echo $mpstat[9]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Losses</th>
    			<td>
    			<div id="losses" class="click" style="display: inline">
    			<? echo $mpstat[10]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Win to Loss Ratio</th>
    			<td>
    			<div id="win_loss_ratio" display: inline">
    			<? echo round($mpstat[9] / $mpstat[10], 2); ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Win Streak</th>
    			<td>
    			<div id="win_streak" class="click" style="display: inline">
    			<? echo $mpstat[13]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Favourite Weapon</th>
    			<td>
    			<div id="fav_weapon" class="weapons_edit" style="display: inline">
    			<? echo $mpstat[14]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Least favourite Weapon</th>
    			<td>
    			<div id="lfav_weapon" class="weapons_edit" style="display: inline">
    			<? echo $mpstat[15]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Favourite Pistol</th>
    			<td>
    			<div id="fav_pistol" class="pistols_edit" style="display: inline">
    			<? echo $mpstat[16]; ?>
    			</div>
    			</td>
    	</tr><tr>
    		<th>Least favourite Pistol</th>
    			<td>
    			<div id="lfav_pistol" class="pistols_edit" style="display: inline">
    			<? echo $mpstat[17]; ?>
    			</div>
    			</td>
    	</tr>
    </table>
    <br>
    <br>
    <? } else { ?>
    <p>You are not logged in. You need to login or register to access this page.</p>
    
    
    <? } ?>
    And the "save-tracker-mp.php" file:

    Code:
    <?
    
    if (isset($_POST["value"]))
    	{
    	#GET DRUPAL API
    	include_once './includes/bootstrap.inc';
    	drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    	global $user;
    
    	#CONNECT TO MYSQL DATABASE
    	$sql_un = "username";
    	$sql_pw = "password";
    	$sql_db = "the-immortality_com_tracker-codwaw";
    	mysql_connect("127.0.0.1", $sql_un, $sql_pw);
    	mysql_select_db($sql_db) or die("Unable to connect to CoD-WaW Tracker database.");
    
    	#GET POST'D VALUES
    	$id = $_POST["id"];
    	$value = $_POST["value"];
    
    	if ($id == "prestige")
    		{
    		#UPDATE MYSQL DATABASE
    		mysql_query("UPDATE multiplayer SET $id='$value' WHERE uid ='$user->uid'") or die(mysql_error());
    
    		#CHECK IF USER ENTERED NOT PRESTIGED OR 1 TO 10
    		if ($value == "Not Prestiged")
    			{
    			echo $value;
    			}
    			else
    			{
    			echo '<img src="http://www.warhawkinfo.com/images/prestige_icons/prestige' . $value . '.png">';
    			}
    		}
    	else
    		{
    		#UPDATE MYSQL DATABASE
    		mysql_query("UPDATE multiplayer SET $id='$value' WHERE uid ='$user->uid'") or die(mysql_error());  
    
    		#ECHO BACK TO JEDITABLE
    		echo $value;
    		}
    	}
    else
    	{
    	echo 'This page can not be accessed directly!';
    	}
    
    ?>
    Anyone have any ideas how I could make this work? Any help is greatly appreciated!

    Kind regards,
    Liam.
    Last edited by Ivaked; 06-17-2009 at 10:38 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •