PHP - Php Elo Calculator
There's one that I've found...but I'm just struggling applying it to what I'm doing.
The idea is to have x number of teams, all starting with 1000 Ranking points. If team A plays team B and wins 1-0, team A should increase by 30 points, and team B should decrease by 30 points? (I think.. ) Then to rank the teams based on their points. The main problem is, I'd like to use a form to edit the teams. I've got as far as a drop down menu to choose the teams, and then Home goals and Away goals. It will already define what is a win/draw/loss. The Calculator code is: <?php class elo_calculator { public function rating($S1,$S2,$R1,$R2) { if (empty($S1) OR empty($S2) OR empty($R1) OR empty($R2)) return null; if ($S1!=$S2) { if ($S1>$S2) { $E=120-round(1/(1+pow(10,(($R2-$R1)/400)))*120); $R['R3']=$R1+$E; $R['R4']=$R2-$E; } else { $E=120-round(1/(1+pow(10,(($R1-$R2)/400)))*120); $R['R3']=$R1-$E; $R['R4']=$R2+$E; }} else { if ($R1==$R2) { $R['R3']=$R1; $R['R4']=$R2; } else { if($R1>$R2) { $E=(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120))-(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120)); $R['R3']=$R1-$E; $R['R4']=$R2+$E; } else { $E=(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120))-(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120)); $R['R3']=$R1+$E; $R['R4']=$R2-$E; }}} $R['S1']=$S1; $R['S2']=$S2; $R['R1']=$R1; $R['R2']=$R2; $R['P1']=((($R['R3']-$R['R1'])>0)?"+".($R['R3']-$R['R1']):($R['R3']-$R['R1'])); $R['P2']=((($R['R4']-$R['R2'])>0)?"+".($R['R4']-$R['R2']):($R['R4']-$R['R2'])); return $R; }} ?> Similar Tutorialsis there a way for php to calculate age based on birthdate with mm/dd/yyyy format? or do I need some converter? if so, how? Hi there, I'm trying to create a land transfer tax calculator. The formula is to be as follows Up to and including $55,000.00 0.5% plus $55,000.01 to $400,000.00 1.0% plus Over $400,000.00 2.0% FOR EXAMPLE: A home with a consideration value of $500,000.01 MLTT Rate Calculation 0 to $55,000.00 55,000.00 x 0.005 = $275.00 $55,000.01 to $400,000.00 $344,999.99 x 0.01= $3,450.00 $400,000.01 to $500,000.00 $99,999.99 x 0.02= $2,000.00 Total MLTT= $5,725.00 what I have so far is Code: [Select] <form method="GET" name="tax" action="http://www.abc.com/what-can-i-afford/"> <input type="hidden" name="comp_form" value="1"> <table cellpadding="2" cellspacing="0" border="0" width="100%" align="center"> <tr valign="top" bgcolor="#eeeeee"> <td align="right" width="150px">Home Cost</td> <td><input type="text" size="10" name="home_cost" value="<?php echo $home_cost; ?>"> (In Dollars)</td> </tr> <tr><td> </td></tr> <tr><td><input type="submit" value="Calculate"><br> <?php if ($comp_form) { print("<a href=\"" . $_SERVER['PHP_SELF'] . "\">Start Over</a><br>"); } ?><br></td> </tr> </table> <?php /* -----------------------------------------------*/ /* Affordability Calc */ /* Set Form DEFAULT values */ $home_cost = 0; /* Set the USER INPUT values */ if (isset($_REQUEST['comp_form'])) { $home_cost = $_REQUEST['home_cost']; if ($home_cost >= 55000) { $MLTT = 55000 * 0.005; if ( ($home_cost >= 55000.01) && ($home_cost <= 400000.01) ) { $MLTT = $MLTT + (($home_cost - 55000)*0.01); if ( ($home_cost >= 400000.01) && ($home_cost <= 500000) ) { $MLTT = $MLTT + (($home_cost - 400000.01)*0.02); } } echo $MLTT; } ?> <h2>MLTT is:<?php $MLTT ?></h2> <?php } ?> I'm only getting 275??? Please help as I'm unsure how to break up the home amount and perform each calculation Im after a little bit of help with two things in my code. www.1pw.co.uk/demo2.php 1) getting an image to appear opposed to just the filename. where and how in my code should i put <img src="filename" /> in the img column of mysql database i am just listing filenames. should i wrap these in the html above instead? 2) how can i get my calculator to behave? i get the correct tally when checking out (using order.php), but as you will see from the link provided the calculator does not work properly, in demo2.php -- addtocart2.php -- Code: [Select] <?php define('INCLUDE_CHECK',1); require "../connect2.php"; if(!$_POST['img']) die("There is no such product!"); $img=mysql_real_escape_string(end(explode('/',$_POST['img']))); $row=mysql_fetch_assoc(mysql_query("SELECT * FROM internet_shop WHERE img='".$img."'")); $jsonArr = array('img' => $row['img'], 'status' => 1, 'id' => $row['id'], 'price' => $row['price'], 'txt' => ' <table width="100%" id="table_'.$row['id'].'"> <tr> <td width="40%">'.$row['img'].'</td> <td width="20%">'.$row['name'].'</td> <td width="10%">$'.$row['price'].'</td> <td width="15%"> <select name="'.$row['id'].'_cnt" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option></slect> </td> <td width="15%"><a href="#" onclick="remove('.$row['id'].');return false;" class="remove">remove</a></td> </tr> </table>'); echo json_encode($jsonArr); ?> --- demo2.php --- Code: [Select] <?php define('INCLUDE_CHECK',1); require "connect2.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shop</title> <link rel="stylesheet" type="text/css" href="demo.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="jquery.ui.main.js"></script> <!--[if lt IE 7]> <style type="text/css"> .pngfix { behavior: url(pngfix/iepngfix.htc);} .tooltip{width:200px;}; </style> <![endif]--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="simpletip/jquery.simpletip-1.3.1.pack.js"></script> <script type="text/javascript" src="script2.js"></script> </head> <body> <div id="main-container"> <div class="tutorialzine"> <h1>Shopping cart</h1> <h3>The best products at the best prices</h3> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Products</span> </span> <div class="content-area"> <div class="content drag-desired"> <?php $result = mysql_query("SELECT * FROM internet_shop"); while($row=mysql_fetch_assoc($result)) { echo '<div class="product"><a href="#" class="item"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" /></a></div>'; } ?> <div class="clear"></div> </div> </div> <div class="bottom-container-border"> </div> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Shopping Cart</span> </span> <div class="content-area"> <div class="content drop-here"> <div id="cart-icon"> <img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" /> <img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" /> </div> <form name="checkoutForm" method="post" action="order.php"> <div id="item-list"> </div> </form> <div class="clear"></div> <div id="total"></div> <div class="clear"></div> <a href="" onclick="document.forms.checkoutForm.submit(); return false;" class="button">Checkout</a> </div> </div> <div class="bottom-container-border"> </div> </div> </div> <div class="bowlpic"> </div> </body> </html> -- script2.js -- Code: [Select] var purchased=new Array(); var totalprice=0; $(document).ready(function(){ $('.product').simpletip({ offset:[40,0], content:'<img src="img/ajax_load.gif" alt="loading" style="margin:10px;" />', onShow: function(){ var param = this.getParent().find('img').attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = this.getParent().find('img').attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } this.load('ajax/tips.php',{img:param}); } }); $(".product img").draggable({ containment: 'document', opacity: 0.6, revert: 'invalid', helper: 'clone', zIndex: 100 }); $("div.content.drop-here").droppable({ drop: function(e, ui) { var param = $(ui.draggable).attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } addlist(param); } }); }); function addlist(param) { $.ajax({ type: "POST", url: "ajax/addtocart2.php", data: 'img='+encodeURIComponent(param), dataType: 'json', beforeSend: function(x){$('#ajax-loader').css('visibility','visible');}, success: function(msg){ $('#ajax-loader').css('visibility','hidden'); if(parseInt(msg.status)!=1) { return false; } else { var check=false; var cnt = false; for(var i=0; i<purchased.length;i++) { if(purchased[i].id==msg.id) { check=true; cnt=purchased[i].cnt; break; } } if(!cnt) $('#item-list').append(msg.txt); if(!check) { purchased.push({id:msg.id,cnt:1,price:msg.price}); } else { if(cnt>=3) return false; purchased[i].cnt++; $('#'+msg.id+'_cnt').val(purchased[i].cnt); } totalprice+=msg.price; update_total(); } $('.tooltip').hide(); } }); } function findpos(id) { for(var i=0; i<purchased.length;i++) { if(purchased[i].id==id) return i; } return false; } function remove(id) { var i=findpos(id); totalprice-=purchased[i].price*purchased[i].cnt; purchased[i].cnt = 0; $('#table_'+id).remove(); update_total(); } function change(id) { var i=findpos(id); totalprice+=(parseInt($('#'+id+'_cnt').val())-purchased[i].cnt)*purchased[i].price; purchased[i].cnt=parseInt($('#'+id+'_cnt').val()); update_total(); } function update_total() { if(totalprice) { $('#total').html('total: $'+totalprice); $('a.button').css('display','block'); } else { $('#total').html(''); $('a.button').hide(); } } -- order2.php -- Code: [Select] <?php define('INCLUDE_CHECK',1); require "connect2.php"; if(!$_POST) { if($_SERVER['HTTP_REFERER']) header('Location : '.$_SERVER['HTTP_REFERER']); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="demo.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="simpletip/jquery.simpletip-1.3.1.pack.js.txt"></script> <script type="text/javascript" src="script2.js"></script> </head> <body> <div id="main-container"> <div class="container"> <span class="top-label"> <span class="label-txt">Your order</span> </span> <div class="content-area"> <div class="content"> <?php $cnt = array(); $products = array(); foreach($_POST as $key=>$value) { $key=(int)str_replace('_cnt','',$key); $products[]=$key; $cnt[$key]=$value; } $result = mysql_query("SELECT * FROM internet_shop WHERE id IN(".join($products,',').")"); if(!mysql_num_rows($result)) { echo '<h1>There was an error with your order!</h1>'; } else { echo '<h1>You ordered:</h1>'; while($row=mysql_fetch_assoc($result)) { echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>'; $total+=$cnt[$row['id']]*$row['price']; } echo '<h1>Total: $'.$total.'</h1>'; } ?> <div class="clear"></div> </div> </div> <div class="bottom-container-border"> </div> </div> </div> </body> </html> Hi! Need some help with a piece of code. New to this, so it is quite a pain in the ass! I need to make a code that shows the what spare change you should give back. so for example. when i put in 7 it should give back: 1 x 5 euro 1 x euro Which it does. but i have some trouble putting in the 1 euro's. for example when i put in 21 it gives back 2 x 10 euro Who can help me out? <?php function results($value) { if ($value >= 10) { echo floor($value / 10) . ' X 10 euro ' . PHP_EOL; $modulf = $value % 10; if ($modulf >= 5) { echo floor($modulf / 5) . ' X 5 euro ' . PHP_EOL; $modult = $modulf % 5; if ($modult >= 2) { echo floor($modult / 2) . ' X 2 euro ' . PHP_EOL; } } } else if ($value >= 5) { echo floor($value / 5) . ' X 5 euro ' . PHP_EOL; $modult = $value % 5; if ($modult >= 2) { echo floor($modult / 2) . ' X 2 euro ' . PHP_EOL; } } else if ($value >= 2) { echo floor($value / 2) . ' X 2 euro ' . PHP_EOL; } else if ($value >= 1) { echo floor($value / 1) . ' X 1 euro ' . PHP_EOL; } } if (count($argv) > 1) { $input = $argv[1]; if (!(is_numeric($input))) { echo 'Geen wisselgeld' . PHP_EOL; } else { $input = intval($argv[1]); if ($input !== 0) { results($input); } else { echo 'Geld wisselgeld' . PHP_EOL; } } } else { echo 'Geen wisselgeld' . PHP_EOL; }
First of all hi everyone, this is my first post as you can see. And i have my first task in PHP, now i warn you i have no experience or know-how whatsover in PHP so please bear with me. My first task is to extend some PHP code to add some functions. the code weve been given already is capable of mutiplication of two variables x and y. Here it is anyway. 1. View the code and copy/paste it into an editor and save it to your own workspace. 2. Extend the script to perform the four basic arithmetic functions : +, -, *, / and return a result. 3. Extend the script again to move the calculations into a function and make use of this function. Code: [Select] <?php /* ====================================================== PHP Calculator example using "sticky" form (Version 1) ====================================================== Author : P Chatterjee (adopted from an original example written by C J Wallace) Purpose : To multiply 2 numbers passed from a HTML form and display the result. input: x, y : numbers calc : Calculate button pressed Date: 15 Oct 2007 */ // grab the form values from $_HTTP_POST_VARS hash extract($_GET); // first compute the output, but only if data has been input if(isset($calc)) { // $calc exists as a variable $prod = $x * $y; } else { // set defaults $x=0; $y=0; $prod=0; } ?> <html> <head> <title>PHP Calculator Example</title> </head> <body> <h3>PHP Calculator (Version 1)</h3> <p>Multiply two numbers and output the result</p> <form method="get" action="<?php print $_SERVER['PHP_SELF']; ?>"> x = <input type="text" name="x" size="5" value="<?php print $x; ?>"/> y = <input type="text" name="y" size="5" value="<?php print $y; ?>"/> <input type="submit" name="calc" value="Calculate"/> <input type="reset" name="clear" value="Clear"/> </form> <!-- print the result --> <?php if(isset($calc)) { print "<p>x * y = $prod</p>"; } ?> </body> </html> Firstly how do i run this code, i have Xamp installed if thats any good? Secondly, do i need two seperate files. i.e. calculator.php for the php code and calculator.html for the form? Thirdly i have no idea how to implement the divide, add and subtract functions. should i do a drop down menu where the user should select what operator they want? or is it more simple than that. Any help greatly appreciated. Please let me know if this post is okay. Hey there, I recently started working on a PHP calculator, I tryed testing it out and the script is not executing... *NOTE* I found the error, I forgot to assign values to the options, all is good now Code: [Select] <?php /* Script Created by: Far Cry Started: August 20th, 2010 10:51 PM PST Completed */ $title = "Calculator"; $form = "<form action='calculator.php' method='POST'> <table> <tr> <td><input name='firstnumber' type='text'></td> </tr> <tr> <td><input name='secondnumber' type='text'></td> </tr> <tr> <td><select name='operation'> <option name='multiply'>*</option> </select></td> </tr> <tr> <td><input name='submitbtn' type='submit' value='Calculate!'></td> </tr> </table> </form>"; if ($_POST['submitbtn']){ $first = ($_POST['firstnumber']); $last = ($_POST['secondnumber']); $operation = ($_POST['operation']); } if ($operation == 'multiply'){ echo"The answer is " . $first * $last . $form; } echo $form; ?> Thanks in advance. hi ! I'm not a PHP master, now i'd like to program an online calculator on my website. it's not the classical calculator with + / - / x / ln etc... but a specific, simple though, calculator. I'd like even to be able to export the results of the calculations into a xls or csv file (that would be the next step) Is that possible to do that with PHP ? or i should look more at javascript or java (dont like that idea) or flash etc... Thanks for your replies ! Website: http://novacms.vacau.com/index.php I'm trying to make a calculator for this game I play, it's fully developed, but with one bug. It doesn't do the math right. $goal = The amount of EXP (Experience Points) someone wants to get $exp = The amount of EXP they currently have $npcs_exp["exp"] = The amount of EXP the monster has But, when they enter in the information, the calculation is all screwed up. When I do it, it seems to give me the same number EACH time. The part where the calculation "goes down". Remember, I'm trying to see how many times you need to kill a NPC to achieve your goal. //math $npc_exp_extract = mysql_query("SELECT exp FROM npcs WHERE name='$npc'"); $npcs_exp = mysql_fetch_assoc($npc_exp_extract); $amount = $goal / $npcs_exp["exp"]; Full code: <?php $exp = $_POST["exp"]; $npc = $_POST["npc"]; $goal = $_POST["goal"]; mysql_connect("removed", "removed", "removed"); mysql_select_db("a2248602_npcs"); if(!$goal || !$npc || !$exp) { echo "<center><form action='index.php' method='POST'>GOAL: <input type='text' name='goal'> Current XP: <input type='text' name='exp'>"; echo "NPC: <select name='npc'>"; $npc_extract = mysql_query("SELECT * FROM npcs"); while($npcs = mysql_fetch_assoc($npc_extract)) { echo "<option name='". $npcs['name'] ."'>". $npcs['name'] ."</option>"; } echo "</select> <input type='submit'></form></center>"; } else { //math $npc_exp_extract = mysql_query("SELECT exp FROM npcs WHERE name='$npc'"); $npcs_exp = mysql_fetch_assoc($npc_exp_extract); $amount = $goal / $npcs_exp["exp"]; if($amount=="1") { echo "You will need to kill a <b/>". $npc ."</b> <b>". $amount ."</b> more time. You earn ". $npcs_exp["exp"] ." XP for each kill from this NPC. | <a href='index.php'>Do another</a><br/><br/>"; } else { echo "You will need to kill a <b/>". $npc ."</b> <b>". $amount ."</b> more times. You earn ". $npcs_exp["exp"] ." XP for each kill from this NPC. | <a href='index.php'>Do another</a><br/><br/>"; } } echo "<center>Made by Zaros from <a href='creation-x.net'>Creation-X</a></center>"; ?> Mod edit: DB credentials removed. Hello People. I would like to build a small calculator in php for my website. Basically what it does is give a form to the user that looks like this The formula is as follows. number_from_box1 * number_from_box2 =result1 then take result1 *52 =result2 now take 60,000 /result2 =result3 Take result3 and make it a number with only 2 decimal places =result4 Then display the result on the form like this Your warranty would be "result4" years I know that there are some really good coders on here. Please could one of you talented people tell me what is the php to do the above on my site? Hi Guys I need a PHP function to which I pass two postcodes and it works out the road distance, I dont mind using google or any other API I have managed to fing JS ways and php functions using crow route but I really really need a traffic distance in PHP Please advice, Help Thank you |