PDA

View Full Version : More Help(!)



Gayowulf
December 6th, 2001, 03:31
I am on a quest:

I am learning PHP properly, and making up assignments for myself.

So far I have completed a counter, and a few other simple things.

My next project, which I have no Idea ho to start, is to make a thing similar to what some hosts have to calculate the price of a custom account.



script language="javascript">
<!--
var name= prompt('Please enter the amount of MB you require.');
document.writeln('Total Cost $' + name * .0025 + ' Thankyou');
//-->
</script>


thats how I did it in javascript, but I want to do it in PHP, and make it so when the amout goes past a certain point the price per mb comes down by a little.

I also want a couple other fields and have the amont from those fields added up as well

I dont know if I am being clear or not, but thats my plan.

The only problem is I dont know where, or how, to start.

Gonzo
December 6th, 2001, 06:55
<?php
if ($page = cal) {
if ($mb > 100) {
$mb = $mb * 0.0025;
echo "The price is $".$mb.".";
} else {
$mb = $mb * 0.0050;
echo "The price is $".$mb.".";
}
} else {
echo "<form action=page.php?page=cal method=post>
<input type=text name=mb>
</form>";
}
?>



Just fix it up a bit for your needs.

Gayowulf
December 7th, 2001, 02:14
Thanks, Gonzo.

You gave me the general Idea, and I improved upon it. I used isset() instead

I havent tested it; does it look functionable?


<?php
if (isset($mb) || isset($gb)) {
if ($gb > 20 && $mb > 100) {
$cost = ($gb * 1.5) + ($mb *.0025);
echo $gb."GB & ".$mb."MB costs $".$cost;
} else {
$cost = ($gb * 1.5) + ($mb * .0050);
echo $gb."GB & ".$mb."MB costs $".$cost;
}

} else {
echo "<form action=".$PHP_SELF." method=post>
GB<input type=text name=gb>
MB<input type=text name=mb>
<input type=submit>
</form>";}?>

Cheap Bastard
December 7th, 2001, 17:47
Originally posted by Gayowulf
Thanks, Gonzo.

You gave me the general Idea, and I improved upon it. I used isset() instead

I havent tested it; does it look functionable?


<?php
if (isset($mb) || isset($gb)) {
if ($gb > 20 && $mb > 100) {
$cost = ($gb * 1.5) + ($mb *.0025);
echo $gb."GB & ".$mb."MB costs $".$cost;
} else {
$cost = ($gb * 1.5) + ($mb * .0050);
echo $gb."GB & ".$mb."MB costs $".$cost;
}

} else {
echo "<form action=".$PHP_SELF." method=post>
GB<input type=text name=gb>
MB<input type=text name=mb>
<input type=submit>
</form>";}?>

looks fine, but what are you gonna do with MB? Honestly, either pick MB or GB and stick with it. You can always order .1GB or 20,000 MB (drop down menu's would really be great for this... I mean, nobody's gonna order 14.134 GB or something, they'd be ordering .xGB or xGB...) Maybe give a half, 1, 1.5, 2, 2.5, 3,4,5,6,...

Also, could just do

if ($gb) {...
} else { ... }

niv
December 7th, 2001, 18:51
I decided to revise it a bit for you:



<?php
# if-(isset($mb)-||-isset($gb))-{
# if it's set, then you can compare it:
----if-($gb->-20-&&-$mb->-100)-{
--------$cost-=-($gb-*-1.5)-+-($mb-*.0025);
--------echo-$gb."GB & ".$mb."MB-costs-$".$cost;
----}-else-if ($mb || $gb) { # if either are set
--------$cost-=-($gb-*-1.5)-+-($mb-*-.0050);
--------echo-$gb."GB & ".$mb."MB-costs-$".$cost;
----}
---
#}-
else-{
----echo-"<form action=".$PHP_SELF." method=post>
----GB<input type=text name=gb>
----MB<input type=text name=mb>---
<input type=submit>---
</form>";}?>

Gayowulf
December 7th, 2001, 20:06
the form is basically for calculating the cost for MB of space and GB of transfer.