Page 1 of 1

Doing maths in PHP

Posted: Sun Feb 23, 2003 2:59 pm
by Darkside
I know you can download loads of voting polls etc but I wanted to make my own one. just very small but I hit a problem soon as I started.

The first thing I tryed to do was find out 1% off a given total.

Code: Select all

<?
$total = "200";
$p1 = "$total / 100";
echo "$p1"
?>
I was hoping that it would do 200 dived 100 and it would echo the answer. its not as easy as I hoped.
Any help would me nice. just so I can get this started thanks

Posted: Sun Feb 23, 2003 3:13 pm
by twigletmac
Try:

Code: Select all

$total = 200; 
$p1 = $total/100; 
echo $p1;
Mac

Posted: Sun Feb 23, 2003 3:15 pm
by decoy1
You have a few syntax errors. Semicolon in wrong place, double quotes around $total / 100 (that makes it a string), etc.

This is what it should look like

Code: Select all

$total = '200'; 
$p1 = $total / 100; 
echo $p1;
This isn't going to give you 1% either, but thats easy enough to figure.

Here is a link to a thread on another board that will help you out.
http://www.sitepointforums.com/showthre ... adid=54074