my first coding

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
JB4
Forum Commoner
Posts: 33
Joined: Tue Jul 22, 2008 6:07 pm
Location: Utah

my first coding

Post 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>
 
Last edited by JB4 on Sun Jul 27, 2008 2:16 pm, edited 2 times in total.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: my first coding

Post 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:
JB4
Forum Commoner
Posts: 33
Joined: Tue Jul 22, 2008 6:07 pm
Location: Utah

Re: my first coding

Post by JB4 »

Ok, I fixed the link up top, and you should be able to figure it out (just drop down menus)
JB4
Forum Commoner
Posts: 33
Joined: Tue Jul 22, 2008 6:07 pm
Location: Utah

Re: my first coding

Post 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.
Attachments
saga.zip
(131.71 KiB) Downloaded 135 times
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: my first coding

Post 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.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: my first coding

Post 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.
JB4
Forum Commoner
Posts: 33
Joined: Tue Jul 22, 2008 6:07 pm
Location: Utah

Re: my first coding

Post 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?
Post Reply