This is my first post here. I have been developing my own web based game for a few months now after completing Halls' browser based game video series. I never did anything in PHP before this, so I'm a total noob, but I think I'm finally starting to get the hang of it.
What I'm recently trying to do it a trade system similar to the "Grand Exchange" on Runescape (horrible game, I know ... but a very nice trade design concept). With this UserA can go to the Trade screen and say I would like to buy or sell 'x' of 'y' item for 'z' price. This then gets logged into a db table.
Code: Select all
$update_trade = "INSERT into trade (username, stance, quantity, item_name, price) VALUES ('$username','$trade_stance','$trade_quantity','$trade_item_name','$trade_price')";
mysql_query($update_trade) or die("System: Could not update the trade table.");Code: Select all
Tim | Buying | 3 | Vegetables | 15Code: Select all
Tim | Buying | 3 | Vegetables | 15
test | Selling | 3 | Vegetables | 15
Code: Select all
<?php
include_once 'connect.php';
?>
<?php
$buying = "Buying";
$selling = "Selling";
$buying_info_1 = "SELECT * from trade where stance = '$buying'";
$buying_info_2 = mysql_query($buying_info_1) or die ("System: Could not get trade information.");
$selling_info_1 = "SELECT * from trade where stance = '$selling'";
$selling_info_2 = mysql_query($selling_info_1) or die("System: Could not get trade information.");
while($selling_info_3 = mysql_fetch_array($selling_info_2) && $buying_info_3 = mysql_fetch_array($buying_info_2))
{
$buying_username = $buying_info_3['username'];
$selling_username = $selling_info_3['username'];
$buying_item = $buying_info_3['item_name'];
$selling_item = $selling_info_3['item_name'];
if ($buying_item == $selling_item)
{
echo $selling_username . " is selling what " . $buying_username . " is buying.";
}
}
?>