You are here: Re: basic calculations, if/then tutorials « All PHP « IT news, forums, messages
Re: basic calculations, if/then tutorials

Posted by Norman Peelman on 09/28/63 11:42

"Newbie Supreme" <newbiesupreme@yahoo.com> wrote in message
news:qbidneQcLK71OorZRVn-jw@comcast.com...
> I'm practicing using form fields to add, subtract, multiply, etc., and
send
> that data to pages as well as to email scripts. It seems I'm decent with
> basic calculations, but when it comes to things like adding an amount if a
> certain checkbox is clicked, or using if/thens, I'm totally at a loss.
>
> Can anyone show me the php used to do the following:
>
> Page 1 has Field1, Field2, and Field3, all textboxes. It also has Check1
> and Check2 These are checkboxes.
>
> How can page two show the result of:
>
> ((Field1 + Field2) x Field3) + 300 if Check1 is checked (0 if not) + 100
if
> Check2 is checked (0 if not)
>
> For example, if on the 1st page the user puts 10 in Field1, 5 in Field2,
and
> 4 in Field3, then checks Check2, the result is 160 (10 + 5, multiplied by
4,
> then adding 100).
>
> Any help is appreciated, or if you know of a website that shows
caluclations
> with form fields in PHP, going from basic to complex, I would love to find
> it. I found one for ASP that was very helpful, it shows the code and had
> example pages for progressively more complicated calculations, with very
> small increments of difficulty, so you could learn very quickly.
>
> Thanks for reading.
>
>

minus any error checking:

---

if (isset($_REQUEST['Check1']))
{
$tmp = 300;
}
elseif(isset($_REQUEST['Check2']))
{
$tmp = 100;
}
else
{
$tmp = 0;
}

/* you can also do this shortform once you get the hang of it
$tmp = isset($_REQUEST['Check1']) ? 300 : isset($_REQUEST['Check2']) ? 300 :
0;
*/

$result = (($_REQUEST['Field1'] + $_REQUEST['Field2']) *
$_REQUEST['Field3']) + $tmp;

echo $result;
---


Norm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация