Crafting Application

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
groog
Forum Newbie
Posts: 15
Joined: Wed Jun 18, 2008 11:48 am

Crafting Application

Post by groog »

I hope this is in the right forum :?
First post :D

As you will soon realize, I'm not a php pro. I'm pretty novice but I'm trying to learn. I've watched a lot of youtube videos and have a book ("PHP and MySQL for Dynamic Websites"). But honestly the videos help a lot more :P

Anyway here is my problem I hope you can help me with. There is this game I used to play a lot and haven't really anymore but I want to make a help site for it because there isn't one and I think it could be a big hit (maybe get some ad money off it *wink* *wink*). And the first thing I wanted to make was a crafting calculator. Simply pick the the item you are wanting to craft from a drop down list, type in the quantity, and hit "Calculate". I started simple with an item that only has one material required (stronger weapons and armors have 15-20 materials needed). And this is how I went about doing it. After watching several array tutorials I made an array with two weapons, bamboo sword and bamboo spear.

Code: Select all

 
$item = array('Bamboo Sword' => $bamboo_sword , 'Bamboo Spear' => $bamboo_spear);
The value for both $bamboo_sword and $bamboo_spear (because materials needed are the same) are both-

Code: Select all

 
$bamboo_sword = array('bamboo' => 10);
$bamboo_spear = array('bamboo' => 10);
 
And I need each item to be an array because eventually it's going to get more complicated. Like-

Code: Select all

 
$example_item = array('cowhide' => 50 , 'steal' => 15 , 'gold' => 5, etc.);
 
Ok, so with this I made a drop down menu like this-

Code: Select all

 
<form action="luminary_materials_calculator_reciever.php" method="post";
 
<?php
 
$bamboo_sword = array('bamboo' => 10);
$bamboo_spear = array('bamboo' => 10);
$item = array('Bamboo Sword' => $bamboo_sword , 'Bamboo Spear' => $bamboo_spear);
 
echo '<select name="item_select">';
foreach($item as $key => $value)
{
echo "<option value=\"$key\">$key</option>";
}
echo '</select>';
echo '<input type="text" name="quantity" value="0" /><br />';
echo '<input type="submit" value="calculate" />';
?>
</form>
 
This shows a drop down menu with the two items listed and a text box to the right where you can type the quantity. Then under is the submit button. When you hit submit it takes you to the receiving (spelled recieving in the above code :P) page where I'm stumped. How do I make it so the Quantity is multiplied by each of the values in the arrays? And then displayed so it's easy to see
ex:

Copper 80
Iron Ore 40
Cowhide 70
etc.

This is as far as I got-

Code: Select all

 
<?php
echo $_POST["quantity"] * ... WHAT DO I DO?! ;
?>
 
I don't even know if I'm going about this the right way, I don't see how I could do this without arrays because there are over a hundred items and each need many values attached to them. Your help would be very much appreciated. If you want to contact me through instant messenger or email-

MSN: fruzzgle@hotmail.com
AIM: fruzzgle
Email: fruzzgle@gmail.com

Thank you :)

BTW: the game is http://luminary.ijji.com
Just in case someone asks.
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Crafting Application

Post by WebbieDave »

Well, there are ways you could implement this in arrays, but if you're serious about making a "hit" site, you're going to need to move this to a database now, before these arrays become unmanageable. After studying basic table design and SQL, you'll soon see that a database will make things much easier.
groog
Forum Newbie
Posts: 15
Joined: Wed Jun 18, 2008 11:48 am

Re: Crafting Application

Post by groog »

Ok, I will look into that. But I'm not sure I have enough experience so I'll try and make simpler applications.

Thanks you :D
Post Reply