Page 1 of 1

my first coding

Posted: Thu Jul 24, 2008 3:25 pm
by JB4
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

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>
 

Re: my first coding

Posted: Sun Jul 27, 2008 11:12 am
by JAB Creations
I highly recommend making sure your clientside code is valid...
W3C (X)HTML) Validator

I don't usually recommend publicly posting your IP; plus it seems either...
1.) You've turned off or rebooted while I attempted to check out the link.
2.) Your ISP blocks external Apache traffic (but most likely allows you to see yourself via your IP), I'm not sure if Qwest blocks it though. In Florida Verizon/Fios does but Comcast does not.
3.) You're having way too much fun with torrents. :mrgreen:

Also I highly recommend giving us a form, maybe some input elements...you know, so we can actually execute the file to see what it does in the browser. :wink:

Re: my first coding

Posted: Sun Jul 27, 2008 2:24 pm
by JB4
Ok, I fixed the link up top, and you should be able to figure it out (just drop down menus)

Re: my first coding

Posted: Mon Jul 28, 2008 2:09 pm
by JB4
Alright, I just decided to upload everything. Here is all or my stuff.

Please let me know what I could do to improve.

Re: my first coding

Posted: Mon Jul 28, 2008 2:32 pm
by JAB Creations
That looks cool...a database would help you keep track of who has what of course. :wink:

I recommend all lower-case letters without spaces (except for download files like music where formatting counts)...as Linux (you're using a Linux host right?) are case sensitive so it's a jolly good practice to get in to. :mrgreen:

I recommend making sure you're much more organized before posting in this particular forum. Test everything including the links to your own site (if any) in your preview of your post. You may also want to clarify what you're looking for input about. For example everyone loves to give me crap about design when it's the everything else (functionality, efficiency, security, etc) I'm concerned about. I'm not sure what input your looking for. But it does seem to work fine.

Re: my first coding

Posted: Mon Jul 28, 2008 2:40 pm
by Dynamis
I would recommend error checking, highly! I took your page source and changed it around so I could join the Elite faction. welcome.php could handle it fine, and then the redirect to Elite.php failed. Simple make sure on welcome.php, that the values are either Light, Machines, Magic, Nature, Neutral, or War, otherwise through an error stating an illegal faction was chosen, or something along those lines.

Nice work so far though.

Re: my first coding

Posted: Mon Jul 28, 2008 11:41 pm
by JB4
Dynamis wrote:I would recommend error checking, highly! I took your page source and changed it around so I could join the Elite faction.
I figured with there being only certain options (the radio things) that this wouldn't be a problem, though I did think about it.

JAB Creations wrote:That looks cool...a database would help you keep track of who has what of course. :wink:
I don't know anything about databases, but that was in my future plans.
JAB Creations wrote:I recommend all lower-case letters without spaces (except for download files like music where formatting counts)...as Linux (you're using a Linux host right?) are case sensitive so it's a jolly good practice to get in to. :mrgreen:
This is the kind of input I want. Although for now (until I get a hard drive for my server) I'm just running my site off of my desktop computer (windows).
JAB Creations wrote:I recommend making sure you're much more organized before posting in this particular forum. Test everything including the links to your own site (if any) in your preview of your post. You may also want to clarify what you're looking for input about. For example everyone loves to give me crap about design when it's the everything else (functionality, efficiency, security, etc) I'm concerned about. I'm not sure what input your looking for. But it does seem to work fine.
I really just want input on how my coding looks, what I can do to change it to work better/easier, how to get rid of un-needed coding (if possible) etc.
And was their something I didn't test?