Frank,

There's a lot to mention, you might want to look at PHP arithmetic operators for an 
understanding between strings and integers at:
http://www.php.net/manual/en/language.operators.arithmetic.php

You might also want to review the function reference at: 
http://www.php.net/manual/en/functions.php

But since you probably don't want to read the manual. Here are some comments. If you 
have questions, you can mail me directly and we'll if we can get you on the ball at 
[EMAIL PROTECTED]

First off,

You cannot use comparision operaters (<=, >=, >) with strings.  When you put quotes 
around your variable it defines it to php as a string, which translated means that 
it's words, not numbers.  So you could say 
if ("$total" == "lowprice") {
  code code code
}

but not say ("$total" >= 25) {
  code code code
}

Also, you have defined your intergers as strings.  You're much better off with 
comparision operators using only intergers rather than comparing two strings that 
should be intergers.  None of them will work besides == and === anyway if what you're 
comparing are strings


Second, you never define what $Price should be.  Is it $total, or just some magic 
number out of the air?  You need to at least tell php that $price = something.  You 
should also define it in the function definition, like

function Price($total, $price) {
  if ($total <= 25) {
    $total = $total * 3000;
  }  
  $price = $total;
  return $price;
}
echo $price;

Third, with your multiplication statement, you need to define what the result of 
$total * whatever is.  So after your then statement it should be something like then 
$total = $total * 3000 or $newtotal = $total * 3000


Finally, with your if statements, you need to all the things php needs to check to 
pass the if statement in parathesis.  So it should be
if ($total >= 25 &&(also known as AND) $total <= 49) then do whatever


For ease of reading, you might just want to put your if statement in brackets, i.e. if 
($total >= 25 && $total <= 49) {
  code code code
}


-----Original Message-----
From: Frank Tudor [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 13, 2003 10:40 AM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] PHP My first function (help)!!!!


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

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to