PHP - Calculations No Longer Working.
Ok, I made some changes to my code (change in variable names only) and now it doesn't seem to work.
Here is the code. <?php if ($_REQUEST['postal'] != "" && $_REQUEST['lbs'] != "") { $postal = $_REQUEST['postal']; $lbs = $_REQUEST['lbs']; $type = $_REQUEST['type']; if ($type == "splist") { $ztype = "cansp_zone" ; $lbstype = "sp"; } else { $ztype = "canmp_zone"; $lbstype = "mp"; } $qP1 = "SELECT * FROM " . $dbprefix . "_canzones WHERE canzone_postal = '$postal' "; $which = $handle_db2; $rsP1 = mysql_query($qP1,$which); if (mysql_num_rows($rsP1) > 0) { $row1 = mysql_fetch_array($rsP1); extract($row1); $prov = trim($canzone_prov); $zone = trim($canzone_zone); $dzone = $ztype.$zone; $dlbs = "can" . $lbstype . "_lbs"; $query = "SELECT $dzone FROM " . $dbprefix . "_can" . $type . " WHERE $dlbs = '$lbs' "; $which = $handle_db2; $result = mysql_query ($query,$which); $row = mysql_fetch_array($result); $dzone = $row[0]; $qP3 = "SELECT * FROM settings WHERE storeid = '$dbprefix' "; $which = $handle_db2; $rsP3 = mysql_query($qP3,$which); $row3 = mysql_fetch_array($rsP3); extract($row3); $taxsetting = trim($taxsetting); $gst = trim($gst); $pst = trim($pst); $hst = trim($hst); $cp_fuelcharge = trim($cp_fuelcharge); $cp_markup = trim($cp_markup); include("./inc/taxcalc.php"); include("./inc/markcalc.php"); ./inc/markcalc.php is as follows: <?php if ($cp_markup != "") { $cp_mark = ($dzone * ($cp_markup / 100)); When I output $cp_mark, it comes out as the same value as $cp_markup Any ideas? Similar TutorialsHi, thanks in advance for any help here. I have a PHP 'contact us' form on my website that recently stopped returning the information that gets entered into the form. I don't know why it's no longer working and was hoping someone here could help. It's worked for the last 4 years and only stopped working within the last week. I still get the email, but none of the information is returned, only blanks. Any ideas? Here's the script I'm using: Code: [Select] <?php /*----------------------*/ /* URL of the site. */ /*----------------------*/ $site_URL = "http://www.Website.com/"; /*----------------------*/ /* Name of the site. */ /*----------------------*/ $site_Name = "Website.com"; /*----------------------*/ /* ADMIN email id. */ /*----------------------*/ $admin_from = "webmaster@Website.com"; /*----------------------*/ /* ADMIN email id to which comments are sent. */ /*----------------------*/ $admin_email = "info@Website.com"; $name = $_REQUEST["firstname"]; $lastname = $_REQUEST["lastname"]; $email = $_REQUEST["email"]; $zipcode = $_REQUEST["zipcode"]; $phone = $_REQUEST["phone"]; $message = $_REQUEST["message"]; $subject = "$site_Name has Received your Message"; $sendmessage = "<font face='tahoma, verdana, arial, helvetica' size=2>New Comments Received...<br><br>"; $sendmessage .= "<strong>Name:</strong> $name $lastname<br>"; $sendmessage .= "<strong>Zipcode:</strong> $zipcode<br>"; $sendmessage .= "<strong>Phone:</strong> $phone<br>"; $sendmessage .= "<strong>Email:</strong> <a href='mailto:$email' style='color:#6095cc; text-decoration: none;'>$email</a><br>"; $sendmessage .= "<strong>Message:</strong> $message<br>"; $sendmessage .= "<br><a href='$site_URL' target=_blank>$site_Name</a></font>"; $headers = "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type $headers .="From: $site_Name Registration <$admin_from>\n"; mail($admin_email, $subject, $sendmessage, $headers); $reply_msg = "<font face='tahoma, verdana, arial, helvetica' size=2>Thank you for your comments at $site_Name. We will reply soon!<br>"; $reply_msg .= "<br>- <a href='$site_URL' target=_blank>$site_Name</a></font>"; $headers = "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type $headers .="From: $site_Name<$admin_from>\n"; // send an email to confirm the referer. mail($email, "$site_Name - Your comments have been received!", $reply_msg, $headers); ?> <center> <font face='tahoma, verdana, arial, helvetica' color='#333333'> <h2> <?=$site_Name?> </h2> <p><font size="2" face="Arial, Helvetica, sans-serif"><strong>Please wait while your comments are being sent.</strong>.<br /> If your page does not refresh automatically, <a href="<?=$site_URL?>">Click Here</a>.</font></p> </center> <script language="javascript"> window.location.href = "<?=$site_URL?>"; </script> MOD EDIT: [code] . . . [/code] BBCode tags added. I've written a small ELO class for calculating a players rating for a game league, and for the life of me I don't know why these calculations are coming up wrong. The Class:
Code for testing:
The output i'm getting is as follows, when they should match what i've stated above (as done on paper with a calculator) Player A (1000) has a 9% Chance of winning. Player B (1000) has a 9% chance of winning. Player A's new rating will be 1029 if they win. Player B's new rating will be 1029 if they win. Player A's new rating will be 997 if they lose. Player B's new rating will be 997 if they lose. I've tried re-writing the calculation over and over but just can't get it. I used the Wikipedia page to get my calculations. I've not added K Factor yet but I will be at some point. Hi, I have been set a task to use 300000 values from a csv to find the total amount of the values and the averages of the values (mode, mean and median). The csv is set into 2 columns, number and amount with 300000 records for each. I am unsure as to how to use only the values from one of the columns in order to get the results i need. Below is the code I have so far; Code: [Select] $filepath = "testdata.csv"; $file = fopen($filepath, "r") or die("Error opening file"); $i = 0; while(($line = fgetcsv($file)) !== FALSE) { if($i == 0) { $c = 0; foreach($line as $col) { $cols[$c] = $col; $c++; } } else if($i > 0) { $c = 0; foreach($line as $col) { $data[$i][$cols[$c]] = $col; $c++; } } $i++; } //this prints the whole of the data still while (($cols[1])) print_r($data); //this still prints all the data!! while ($data) print_r($cols[1].$data); Am I going about this wrong by using an associative array? Hello, I am trying to take the calculations of two variables to create a new data for a new variable. For example.....
LRH_calcLevel($LRH_current, $LRH_bankfull); +/- $LRH_totalDepth = $newVar
Which should translate to -10.43 Ft +/- 40 = $newVar (-29.57) <----- What I want
Instead it is showing up as 10.43 Ft +/- 40 = $newVar (-50.43) <----- How it is displaying which is incorrect
Here is the code I am using. The second function is what I am trying to use to create the new variable data based on the calculations above from the data provide via XML. How can I get this to display correctly?
-Thanks
//Parse Lake Ray Hubbard XML Data $site = simplexml_load_file($LRH_data);{ $LRH_bankfull = '435.5'; $LRH_totalDepth = '40'; $LRH_current = $site->observed->datum[0]->primary; $LRH_vaild = $site->observed->datum[0]->valid; $LRH_updated = DATE("D, M d, g:i a", STRTOTIME($LRH_vaild)); } //Lets calculate the lake depatures from full pool for Lake Ray Hubbard function LRH_calcLevel($LRH_current, $LRH_bankfull) { //Get float values from strings $LRH_current = floatval($LRH_current); $LRH_bankfull = floatval($LRH_bankfull); //Calculate the difference $LRH_calcLevel = $LRH_current - $LRH_bankfull; //Format difference to two decimal places and add 'Ft' $LRH_calcLevelStr = (string) number_format($LRH_calcLevel, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcLevel>0) { $LRH_calcLevelStr = '+'.$LRH_calcLevelStr; } //Return the calculated formatted value return $LRH_calcLevelStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = $LRH_current; $val2 = $LRH_bankfull; $LRH_prec = ( $val1 / $val2) * 100; // 1 digit after the decimal point $LRH_prec = round($LRH_prec, 1); //Lets convert the depature from full pool for Lake Ray Hubbard function LRH_calcDepth($LRH_calcLevelStr, $LRH_totalDepth) { //Get float values from strings $LRH_calcDepthStr = floatval($LRH_calcLevelStr); $LRH_totalDepth = floatval($LRH_totalDepth); //Calculate the difference $LRH_calcDepth = $LRH_calcDepthStr - $LRH_totalDepth; //Format difference to two decimal places and add 'Ft' $LRH_calcDepthStr = (string) number_format($LRH_calcDepth, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcDepth>0) { $LRH_calcDepthStr = '+'.$LRH_calcDepthStr; } //Return the calculated formatted value return $LRH_calcDepthStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = LRH_calcLevel($LRH_current, $LRH_bankfull); $val2 = $LRH_totalDepth; Hi, I have tried to merge two queries into one however a piece of code keeps coming up with an error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource. It relates to this. I cant see it doesn't work and I have tried around 10 different options but this is the nearest I can get. Can anyone advise me what the problem is and why this no longer works please? while($row = mysql_fetch_assoc($myQuery)) <?php ini_set('display_errors', 1); error_reporting(-1); if( isSet($_GET['description'])) $description = $_GET['description']; if(isSet($_GET['price'])) $price = explode('-',$_GET['price']); $low = (int)$price[0]; $high = (int)$price[1]; ($myQuery = "SELECT * FROM productfeed WHERE 1 . if(isset($description)) ' AND if description = '. $description; if(isset($price)) ' AND if price = '. $price; . "); while($row = mysql_fetch_assoc($myQuery)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; $fulldescription = substr("$fulldescription", 0, 400); echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image' width=\"95%\" /></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } Hi I was wondering if somebody could give me some help. I have a form with the following table for users to input <td width="118" style="text-align: left"><input type="text" name="item1cost"></td> <td width="118" style="text-align: left"><input type="text" name="item1Charge"></td> <td width="118" style="text-align: left"><input type="text" name="item1sum""></td> is there a way to have the 3rd field auto populated by calculations made from the data a user puts in the 1st and 2nd field ? The calculation i am actually looking for i can explain easier in excel terms Lets say item1cost is in A2 Item1charge is in B2 Item1sum is in C3
A3 would be the cell i want populating with the calculation of any help would be greatly appreciated thanks
Hello there, I stuck in a silly logic ... I will really appreciate if someone helps me... My Fiscal year starts from 01st April of current year through 31st March of next year, for ex. (01 Apr 2011 to 31st March 2012). I want to put a latefee of 6.25% on total amount, if the payment date is not done on the current fiscal year. Everything depends on the payment date. For example, A bill of $8000 was generated on 01st Apr. 2009 then its 6.25% will be $500 and the customer is paying the same on 30th August 2011, then total years passed is 3. So, the late fee will be 500 * 2 = $1000. i.e. Any bill generated and paid in the current fiscal year (stated above) is free of late fee and after that the above calculation is applicable. Please help, how to do the calculation. A function is really appreciated. This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=328102.0 Hi guys, I'm working on a project and I can't wrap my head around on a calculation that needs to be done on a multidimensional array. Quick background, it's a hotel benchmarking tool and I need to calculate the market penetration index (MPI). I have an array with 3 main arrays. First 2 are the hotels which are being compared and the last one is the MPI array. Each array contains an array for every month the user selects. Inside THAT array is data that needs to be used for calculations. Here is an example: Code: [Select] Array ( [Competitive set] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 13 [data] => 67.6 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 13 [data] => 63.6 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 13 [data] => 59.2 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 13 [data] => 54.6 ) ) ) [Test] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) [MPI] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) ) Currently the 'data' for MPI is wrong. That needs to become the data of the first array divided by the data of the second array and multiplied by 100 (percentage). How would I go about doing that? The foreach loops are a bit too big for me on this one. // I am trying to calculate the number of days between dates and have a major problem. When I try the example below, it gives me exactly 201 days, yet the dates have different times, meaning that a full day is impossible. If it matters, I am testing via xampp 1.7.3 with php version 5.3.1 with Windows XP. Can anyone explain what I am doing wrong. Can daylight savings play a role? $frmritedate7116 = strtotime('2010-12-13 23:00'); $frmritedate7156 = strtotime('2010-05-27 00:00'); // $frmritedate7251 = $frmritedate7156 - $frmritedate7116; // // 1274943600-1292310000=-17366400 // 86400 seconds in a day ( 201.00 ) // // // I'm sure there is a very simple fix to this problem. I have an image uploader in the backend of my site. Since moving hosts this no longer works. The PHP is if((!empty($_FILES["indeximage"]))) { $indeximagename = basename($_FILES['indeximage']['name']); $indeximagenew = $_SERVER['DOCUMENT_ROOT'] . '/images/uploaded/index/' . $indeximagename; if (!file_exists($indeximagenew)) { if ((move_uploaded_file($_FILES['indeximage']['tmp_name'], $indeximagenew)) === true) { echo $indeximagename; echo ' was successfully uploaded.'; }else { echo 'Unable to move'; echo $indeximagename; echo ' into the right folder.'; } }else { echo 'You did not upload an index image.'; } } I'm guessing the problem is with the document root part. $indeximagenew echos /var/www/vhosts/webaddress.co.uk/httpdocs/images/uploaded/index/imagename.jpg The actual actual address of the image, when on the site, is http://www.webaddress.co.uk/images/uploaded/index/imagename.jpg Any help would be great! Hello, While I am working on my code I faced this problem, which is Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\factory1.php on line 100 Call Stack # Time Memory Function Location 1 0.0062 379160 {main}( ) ..\factory1.php:0 Any help to come over this problem. My database is quite large (600 MB). Thanks in advance. We're moving to a new web server and we recently migrated to a new MS SQL server, as well. All PHP functions on the old web server were switched to point to the new SQL server and all was well. But..... Now I''m trying to move my PHP functions to the new web server and it won't connect to the database. PHP works fine because I can echo "Testing" or whatever. I've downloaded the SQL Server PHP drivers from Microsoft, changed the connection string from MSSQL to SQLSRV, updated the PHP.ini file, and taken several other steps. It still can't see the database. Ideas? Oh, yeah. And both the new web server and MS SQL server are Server 2008 R2. I apologize if this isn't the exact right location for this question, but it's the best place I could find. I work for a small business and the server hosting our website recently disabled FormMail. We no longer have a webdesigner per se and I've been the one taking care of the website. Unfortunately the few programming classes I've taken have mostly left me by now and I'm banging my head against the wall trying to find a way to get back our multiple feedback forms. I'm sure the best thing would be to hire someone, but business hasn't been great and the boss is counting on me, so I'm hoping someone here may have some suggestions. I've been corresponding with our server trying to get some suggestions on what to do and this is the best they've been able to tell me; "The reason being that Shared Servers must have the ability for php/cgi to send mail disabled as a protection against darkmailer, so any form or scripts that would send mail must be able to authenticate itself to the server as a valid user." "If you can find a method to send the mail without php/cgi, or one that does go through the steps to authenticate as a valid user (specifically, as you), then we can probably get you all set up." "The only option at this point would be to correct your script to authenticate as a valid email user." "...you would need to change your scripts to login with a mail user to authenticate and send mail." Now I'm not completely programming illiterate; I mean, I passed my classes in college, but I can't figure out how to do this. They say they don't allow any FormMail or FormMail Clones, so I'm fairly lost. If anyone has any helpful hints or suggestions I would appreciate it greatly. Thanks, Zach This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=333872.0 I had to move hosters recently and I have a couple of scripts run using CRON to backup my MySql database and manage the number of backups that I keep. I can ask the hosters to deprecate the version of PHO backwards but I don't want to lose the opportunity of features that may be available in the new version. The main script essentially performs a MySqlDump to a specified directory and then emails me to tell me that it completed successfully. The second script just deletes any files in the backup folder more than x days old. I know mysqldump is a valid call so I should need to use anything other than that but I'm lost when it comes to seeing what is wrong with my scripts. backup.php
<?
/* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
//$dbuser = $db_user, $conection ; // Database username
$command = "mysqldump -u $db_user --password=$db_password $db_name | gzip > $filename"; copy ($filename, $backdir.$newfile);
unlink($filename); //delete the backup file from the server
and delold.php
<?php
//echo "script is running";
if (is_dir("$path") )
}
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342385.0 I have a 'subscribe' form on a website that uses Ajax to validate the input fields, the form is then processed via php. The actual html code resides on a Wordpress page.
I had actually just got the form to work again. The website was static, and I transferred everything over to Wordpress, and the form didnt work. I was able to get it working by specifying the url: in ajax, as an absolute path to my php form. Overnight, something, I'm not sure what, stopped the form from processing. No data is posted to myql, and no email is sent or received. The status message just hangs at "Please wait while we process your information..." This message is in part of my Ajax code, so I am thinking something is wrong with my php script. I have a 'contact' page that uses nearly identical code that the 'subscribe' pages uses to validate the input fields, and it works.
I was able to recover both the ajax and php script from an earlier time when they did work, I uploaded back to my server and nothing, the form still does not process. I also made sure my database credentials were correct with my host, and even tested my connection to mysql which I was able to connect. Next, I made sure I was able to send mail with my host.
I don't know what is causing the form to hang, and I would love to get this solved; any help would be appreciated!
$start = 0; Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! |