$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
$tip = $details['TotalHouseholds'];
$perc = 21.33%
$sumone= $tip*$perc;

could anyone tell me if this is remotley correct i have tryed it in a browser but i get the page displayed normally with a nice line of code telling me

Warning: Division by zero in /home/sites/miraclehosting.co.uk/public_html/scdc.php on line 179

am bit confused the code is supposed to pull some data from a mysql database and multiply it by 21.33% you would proberlt think it is simple but i am newand i want to cry!!!!

Recommended Answers

All 4 Replies

Member Avatar for diafol
result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
$tip = $details['TotalHouseholds'];
$perc = 21.33%
$sumone= $tip*$perc;

Unfortunately there are quite a few mistakes here:

$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
$details = mysql_fetch_array($result);
$tip = $details['TotalHouseholds'];
$perc = 0.2133;
$sumone= $tip*$perc;

The fact is that $tip and $details['TotalHouseholds'] did not exist as no reference was made to the $result variable (which also needed a '$' sign). Also AFAIK, '%' is used as the "remainder function" for division, e.g. 9%4 = 1 . You must terminate each statement with a ';'.

It should work now, if not, come back.

$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
$tip = $details['TotalHouseholds'];
$perc = 21.33%
$sumone= $tip*$perc;

could anyone tell me if this is remotley correct i have tryed it in a browser but i get the page displayed normally with a nice line of code telling me am bit confused the code is supposed to pull some data from a mysql database and multiply it by 21.33% you would proberlt think it is simple but i am newand i want to cry!!!!

No, this is not remotely correct.

What you declare $perc = 21.33% the php sees it as saying divide 21.33 by undefined, so it tries to divide by 0 and gets this error.
Hint: the % has a special meaning in php to calculate the remainder of a division operation. It's called Modulus

Also where does the $details come from? You have not declared any value for $details.

Anyway, if you want to calculate 21.33 percent of 200 for example, you just have to divide 200 by 100 and multiple by 21.33 like this:
200 / 100 * 21.33
You can then add a percentage sign if you want it to be displayed in result.

Member Avatar for diafol

Ahem uncle, did you read my post?

commented: made me laugh +1

Ahem uncle, did you read my post?

I dunno, but on my view at the moment his is first, yours second
the order is messed up
yours is 3 hours ago
his is 1 hour ago,
database will (damn lost the fingers cross icon) sort it out eventually

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.