Re: PHP My first function (help)!!!!
| From: | David | Date: | Thu, 14 Aug 2003 11:24:37 +0000 |
| Subject: | Re: PHP My first function (help)!!!! | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-21150@lists.php.net to get a copy of this message | ||
Sorry outlook screwed my code a bit
Dear Frank
You probably need to get a book, but here are two examples, one using if statements, and the other
using the switch/case statement.
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
//initialise the $total
$total = 51;
//$TotalString = the return of the function. Pass $total to the function
$TotalString = Price($total);
//Display the total
echo $TotalString;
function Price($ftotal)
{
//add 5 to the function
if ($ftotal <= 30)
{
$ftotal *= 3200;
}
else if($ftotal <= 50)
{
$ftotal *= 4500;
}
else
{
$ftotal *= 6500;
}
//return the value to $TotalString
return $ftotal;
}
?>
</body>
</html>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
//initialise the $total
$total = 51;
//$TotalString = the return of the function. Pass $total to the function
$TotalString = Price($total);
//Display the total
echo $TotalString;
function Price($ftotal)
{
switch($ftotal)
{
case $ftotal <= 30:
$ftotal *= 3200;
break;
case $ftotal <= 50:
$ftotal *= 4500;
break;
default:
$ftotal *= 6500;
}
//return the value to $TotalString
return $ftotal;
}
?>
</body>
</html>
--
Kind Regards
David
Anagram Systems
http://www.anagram-sys.co.uk/
http://www.web-planets.com/davec/techsitedb/
"Frank Tudor" <frank_tudor@yahoo.com> wrote in message news:20030813173939.58326.qmail@web11606.mail.yahoo.com...
> Guys I need help!
>
> I think I am on the right track with my logic but my code fails.
> Can someone help? (my coding is weak no formal training).
>
> Thanks,
> Frank
>
>
> $TotalString = "$total";
> function Price($total)
> {
> if "$total" <= "24" then "$total" * "3200"
> else
> if "$total" >= "25" and "$total" <= "49" then
"$total" *
> "3000"
> else
> if "$total" >= "50" and "$total" <= "99" then
"$total" *
> "2900"
> else
> if "$total" >= "100" then "$total" * "2700"
> return "$Price";
> }
> echo "$Price";
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com