Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Attempting a calc
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
Attempting a calc
Tweet Topic Started: Jul 2 2009, 02:17 AM (212 Views)
Hiddenzbu Jul 2 2009, 02:17 AM Post #1
Member Avatar


Posts:
130
Group:
Member
Member
#812
Joined:
Aug 31, 2008
Well, its not about IF or ZB, but its about coding in general so I believe this topic is still allowed. Anyway, I'm "attempting" to create an online calculator for my site in order to process a certain formula that is found in the Pokemon Games, namely the amount of experience you gain from being a particular foe. I know very some (very limited) PHP but when I started I thought it didn't sound too hard to make. I was horribly wrong, I now feel like I have no idea what I'm doing. I've gone over the W3 pages on PHP several times and can't seem to find exactly what I'm looking here so I'll just concede to look like a doofus and post it here. Basically I want it to process this equation when certain things in the form are selected from the drop down, inputted, or check marked.

EXP = (a x b x L)/ 7

(Note: There are some more stipulations with A but I'm hoping to get help without having to bore you guys about the mechanics of the Pokemon games)

Here is what I have so far, but I'm obviously doing something wrong because I can't even get the thing to process when I hit submit.

Spoiler: click to toggle
<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php#result" method="post">
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_POST["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>
Posted Image
Offline Profile Goto Top
 
Garath531. Jul 2 2009, 09:28 PM Post #2


Posts:
156
Group:
Dedicated
Member
#3,232
Joined:
Jun 17, 2009
Try using either of these two codes:
Spoiler: click to toggle

Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php?result=1" method="post">
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_GET["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>

or
Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php" method="post">
<input type="hidden" name="result" value="1" />
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_POST["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>


Edited by Garath531., Jul 2 2009, 09:28 PM.
I'm back after an unexpected hiatus. If I've forgotten about a code I was working on for you, just drop me a PM and let me know. :)
Offline Profile Goto Top
 
HolySavior Jul 2 2009, 10:04 PM Post #3
Member Avatar
Modifying The World Around You

Posts:
2,488
Group:
Distinguished Coder
Member
#7
Joined:
Jul 2, 2008
Coding language
Everything
if your doing this on the page itself and not submiting any info to a database. just use JavaScript to run the form.
Offline Profile Goto Top
 
Choco Jul 3 2009, 09:13 AM Post #4
Member Avatar
¡ʎɹoʇɔɐɟ ʎʇıʌɐɹƃ ɐ uı pǝddɐɹʇ ɯ,ı 'dןǝɥ

Posts:
589
Group:
Admins
Member
#3,272
Joined:
Jun 30, 2009
Coding language
Everything
Garath531.
Jul 2 2009, 09:28 PM
Try using either of these two codes:
Spoiler: click to toggle

Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php?result=1" method="post">
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_GET["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>

or
Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php" method="post">
<input type="hidden" name="result" value="1" />
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_POST["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>


I can confirm that the second one works -- aquate.us/poke.php. :P
Posted ImageIt's a magical world, Hobbes, ol'd buddy... ...let's go exploring!
In progress: Something Special ;)
Offline Profile Goto Top
 
Hiddenzbu Jul 3 2009, 02:29 PM Post #5
Member Avatar


Posts:
130
Group:
Member
Member
#812
Joined:
Aug 31, 2008
Garath531.
Jul 2 2009, 09:28 PM
Try using either of these two codes:
Spoiler: click to toggle

Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php?result=1" method="post">
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_GET["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>

or
Code:
 

<html>
<body>
<?php

$pokemon = $_POST["pokemon"];
$level = $_POST["level"];
$trade = $_POST["trade"];
$trainer = $_POST["trainer"];
$foreign = $_Post["foreign"];

$result = ($pokemon*$level*(1+$trade+$trainer+$foreign))/7;

?>

<fieldset>
<legend>
EXP Calc
</legend>
<form action="./expcalc.php" method="post">
<input type="hidden" name="result" value="1" />
Pokemon Encountered: <select name="pokemon">
<option value="64">Bulbasaur</option>
<option value="141">Ivysaur</option>
<option value="208">Venusaur</option>
<option value="65">Charmander</option>
</select><br>
Level of Pkmn: <input type="text" name="level" maxlength="3" size="3" value="<?php echo $level; ?>" /><br>
Traded Pokemon? <input type="checkbox" name="trade" value=".5">
<br />
Trainer Battle?
<input type="checkbox" name="trainer" value=".5">
<br />
Foreign Pokemon?
<input type="checkbox" name="foreign" value=".2">
<br />
<input type="submit" value="Submit" />
</form>
</fieldset>

<?php
//Show the result
if ($_POST["result"]) {
printf("<p id=\"result\" class=\"center bigger\">The amount of experienced gain equals %'05s </p>", $result);
}
?>
</body>
</html>


Oh wow thank you very much. But if you don't mind could you give me a brief rundown of the things that you changed, just so I don't have to keep bothering you guys for my future coding endeavors.

And @ holy, I would but even though I barely have any PHP knowledge I have about zero javascript knowledge.
Posted Image
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:46 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy