Last Value

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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Last Value

Post by SidewinderX »

Hello, I didnt realize it till' right now. But I have a code which allows you to select a game from a drop down menu, then select some other choices and then does some math. BUT when you select the game and fill out the other choices and click on the "Get Price" button it refreshes the page and dose some math, but what it does is instead of multiplying by the value it suppose to have, it multiplys by the last value,

Here is my code

Code: Select all

<?php
$db = mysql_connect("localhost", "", ""); 
mysql_select_db("games",$db); 
$result = mysql_query("SELECT * FROM gamesinfo ORDER BY gameName",$db);

if (empty($gameName)) {
echo "<form>";
//Function Chooses the game
print "Select your game: ";
echo "<select name="gameName">";
while($row = mysql_fetch_assoc($result)) 
{ 
  extract($row); 


echo "<option value="$gameName">$gameName</option>\n";
}
echo "</select>";
print "<br><br>"; 
//END


//Function Player Ammount yields the ammount of players to chose from
print "Select the number of players:  ";
$output = '<select name="playerAmmount">'; 
for($i = $minPlayer; $i <= $maxPlayer; $i += 2) {  
$output .= '<option value="'.$i.'">'.$i.'</option>'; 
} 
$output .= '</select>'; 
echo $output; 
print "<br><br>";
//END


//Function determines weather or not the server is to be public or private
print "Choose weather your server is public or private, private servers require passwords to join:";
print "<br>
<select name="pubOrPrv">
<option value="$pubPrice">Public Server
</option>
<option value="$prvPrice">Private Server
</option>
</select>";
print "<br><br>";
//END

//This function displays the optional Team Speak server
print "Optional: Team Speak Voice Server:  
<br>
Chose the server ammount: ";
$output = '<select name="teamSpeak">'; 
$output .= '<option value="No Team Speak Server">No</option>';
for($i = 10; $i <= 50; $i += 2) {
$output .= '<option value="'.$i.' Person Team Speak Server">'.$i.'</option>'; 
} 
$output .= '</select>'; 
echo $output; 
print "<br><br>";
//END
echo "<input type="submit" value="Get Price">";
echo "<input type="reset" value="Reset Form">
</form>";


} else {
echo "<h1>Below are your order details</h1><br><br>";
echo "
Game Name: $gameName
<br><br>
Ammount of Players: $playerAmmount
<br><br>
Public/Private Price: $pubOrPrv
<br><br>
$teamSpeak
<br><br>";

echo "Your Team Speak Voice Server Cost: $";
echo $teamSpeak * .40;
$tsPrc = $teamSpeak * .40;
echo "<br>Your Game Server Cost: \$";
echo $playerAmmount * $pubOrPrv;
$gamePrc = $playerAmmount * $pubOrPrv;
echo "
<br>
Your final price is: \$";
echo $gamePrc + $tsPrc;
echo "<br><br><input type="submit" value="Submit Request">";
echo "<input type="button" onClick="history.back()" value="Back">";
}  
?>
Now that you see the code, im going to explain my problem with examples.

In my database called games, there is a table called gamesinfo, in there right now there are 2 rows

0 | Americas Army | 3.00 | 2.50 | 8 | 64
1 | Counter-Strike | 2.00 | 2.50 | 8 | 64

When I select Americas Army I want it to just deal with row 0 so when it does the math it works with the values 3.00 and 2.50 like-wise when I choose Counter-Strike i want it do deal with values 2.00 and 2.50 dollars. Right now it just deals with the last row, in this case Counter-Strike so in both instances it deals with 2.00 and 2.50 no matter what game is selected.


feyd | THIS IS NOT A TUTORIAL. Moved to PHP - Code
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

You need to re query the databse and get that information back after you've sent the information back to the server. So maybe add something like this after your else:

Code: Select all

extract(mysql_fetch_assoc(mysql_query("SELECT * FROM gamesinfo WHERE gameName='$gameName'")));
and then you can use the prices associated with the specific game.
Post Reply