Jump to content

[SOLVED] Not Calculating RIght


Clinton

Recommended Posts

First off, i know there's a specific thread for Calculations but nobody ever looks there and so stuff gets unanswered for a while. Not only that but if the one person who does look doesn't know then it continues to be left unanswered for more days. So I'm posting here because somebody is bound to know...

 

I cannot figure this damn thing out. I spent probably the last 3 hours working on it changing variables, the calculations, etc. and I just can't get it. THe rest of the table works it is just not calculating correctly but it makes no sense to me. When I perform the calculations I don't have a problem with it. I don't know if it could be something with the elseif? Sometimes the signin could have a number in it, sometimes the signout could have a number in it, sometimes they both could have no numbers in it, but they will never have numbers in both sections at the same time.

 

OK, it's pulling the 'weight' of the item from the previous post. Now, it wasn't updating correctly and I realized that was because I was accounting for the addition or subtraction or the item that this particular page was designed for. So basically I need to take the 'weight' as POSTed, account for the change and then update it.

 

Let's say a car weights 1.3 tons.

 

I've currently got 3 cars in the db so it should say 3.9.

 

I want to take 1 car way so I do that. The variables passed are 'weight' 3.9 and signout '1'.

 

Now, they aren't going to sign things in and out at the same time but I had to figure out a way to incorporate that, that's where the variable grandtotal comes in. If they are signing a car out then signout will be 1 and signout will be 0 and the total will still be 1.

 

Then I need to take that total and times it by the weight of one car. In this case 1.3 * 1 = 1.3.

 

But crazy's don't believe in pounds so I have to convert it to grams. So, 1.3 / 456.... blah blah.

 

Then I have to take the weight as was reported from the POST and either add to it if I"m adding more cars to the inventory or subtract from it if I'm taking cars away.

 

Then I want to enter that total updated weight into the system... and... it's not working. The damned thing hates me. I don't even understand it anymore. It's like I change one variable and it's way off and I change another and it's the opposite of what it's suppose to be. :-| Doesn' t make sense anymore.

 

<?php
session_start();

$tablename = $_POST['tablename'];
$datecode = $_POST['datecode'];
$producttype = $_POST['producttype'];
$transactiondate = $_POST['transactiondate'];
$joblocation = $_POST['joblocation'];
$jobnumber = $_POST['jobnumber'];
$signout = $_POST['signout'];
$signin = $_POST['signin'];
$outinby = $_POST['outinby'];
$weight = $_POST['weight'];
$page = $_POST['page'];
$choice = $_POST['choice'];
$type = $_POST['type'];
$grandtotal = ($signin + $signout);

$powder = mysql_query("SELECT new FROM master WHERE name = '$type'") or die(mysql_error());

if ( $signin == $signout)

echo "<p> </p>";

elseif ( $signin == "")
{

while($sp = mysql_fetch_array($powder)){

$new = $sp['new'];

$totalgrams = ($grandtotal * $new);
$totalgrams = ($totalgrams / 453.59237);
$weight = ($weight - $totalgrams);

}
}
elseif ( $signout == "")
{

while($sp = mysql_fetch_array($powder)){

$new = $sp['new'];

$totalgrams = ($grandtotal * $new);
$totalgrams = ($totalgrams / 453.59237);
$weight = ($weight + $totalgrams);


}

}
else echo "<p> </p>";


$sql2 = "UPDATE weights SET currentweight = '$weight' WHERE tablename = '$tablename'";
echo $sql2;
$result2 = mysql_query($sql2) or die(mysql_error());

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.