my first coding
Posted: Thu Jul 24, 2008 3:25 pm
Can be seen here
I am only going to post the very last page of this, because the rest of it isn't even that hard. SO if you just submit random answers, then the results.php is what I'm posting
I am only going to post the very last page of this, because the rest of it isn't even that hard. SO if you just submit random answers, then the results.php is what I'm posting
Code: Select all
<html>
<head>
<title>
<?php echo $_POST["Unit"]; ?>
</title>
</head>
<body>
<!-- # Sets $URL as the url to the units page -->
<?php
# Figures out if it's either of the two oddball units
if ($_POST["Unit"] == "Ballista") {
$URL = "http://www.sagatraders.com/store/product4.html";
} else if ($_POST["Unit"] == "Fireball") {
$URL = "http://www.sagatraders.com/store/product4.html";
} else {
$URL = "http://www.sagatraders.com/store/CS_" . $_POST["Unit"] . ".html";
}
# extracting the price
$page_source = file_get_contents($URL);
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', $page_source, $groups);
$price = floatval($groups[1]);
# get gold cost
$GOLD1 = "http://www.sagatraders.com/store/3000sagagold.html";
$gold1_page_source = file_get_contents($GOLD1);
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', $gold1_page_source, $gold1_groups);
$gold_price_3000 = floatval($gold1_groups[1]);
# get gold cost
$GOLD2 = "http://www.sagatraders.com/store/product155.html";
$gold2_page_source = file_get_contents($GOLD2);
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', $gold2_page_source, $gold2_groups);
$gold_price_7800 = floatval($gold2_groups[1]);
# Get average gold cost
$gold_price_3000 = $gold_price_3000 * 2.6;
$avg_gold_price = $gold_price_3000 + $gold_price_7800;
$avg_gold_price = $avg_gold_price / 2;
#price per 25 cents because unit pricing is in quarter intervills
$avg_gold_per_quarter = 7800 / $avg_gold_price / 4;
$unit_value = $price / .25 * $avg_gold_per_quarter * $_POST["amount"];
?>
<!-- # Tells you what you searched for -->
<BR>You searched for <?php echo $_POST["Unit"]; ?>.
<!-- # Shows you what the URL is -->
<!-- # <BR><BR>Getting price from <?php echo $URL; ?> -->
<!-- # Tells you how much the unit costs -->
<BR><BR><?php echo $_POST["Unit"]; ?> costs $<?php echo $price ?>
<BR><BR>
<!--/*
<?php echo $gold_price_3000 ?>
<BR>
<?php echo $gold_price_7800 ?>
<BR>
<?php echo $avg_gold_price ?>
<BR>
<?php echo $avg_gold_per_quarter ?>
<BR>
*/-->
<?php echo $_POST["amount"] ?> <?php echo $_POST["Unit"]; ?> is worth <?php echo round($unit_value) ?> Gold.
</body>
</html>