cdoyle Posted April 19, 2008 Share Posted April 19, 2008 Hi, I'm working on another ezRPG page, this one I'm trying to a travel page. I have in my cities table a field called 'cost' What I want it to do is, depending on which city the player chooses to go to, it subtracts the cost from his onhand gold. I just can't seem to get it to work, I can hard code into my page a cost and it subtracts that. But just can't seem to get it to take subtract the amount that I have listed in my Cities table. Here is the code I have so far, <?php /*************************************/ /* ezRPG script */ /* Written by Chris from WA */ /* http://code.google.com/p/ezrpg */ /* http://www.bbgamezone.com/ */ /*************************************/ include("lib.php"); define("PAGENAME", "Wanna Go Somewhere?"); $player = check_user($secret_key, $db); $cityid = $_GET['id']; $query = $db->execute("select `City_ID`, `City_Name`, `Cost` from `Cities` where `City_ID`=?", array($_GET['City_ID'])); $buscost = $query['Cost']; if ($_GET['act'] == "go") { if ($player->gold < $buscost) { include("templates/private_header.php"); echo "Hey everyone look, this wanna be gansta thinks this bus is free!<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; } //if player already in this city If ($player->City_ID == $cityid) { include("templates/private_header.php"); echo "Are you high? You're already here moron<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; } else { //update City $query1 = $db->execute("update `players` set `City_ID`=?, `gold`=? where `id`=?", array($cityid, $player->gold - $buscost, $player->id)); } $player = check_user($secret_key, $db); include("templates/private_header.php"); echo "You have arrived at your destination"; echo "<p><a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; } include("templates/private_header.php"); echo "Welcome to CAC Bus Lines<br>"; echo "Please purchase your ticket and step onto the bus. <br /> The cost of the ticket from your current location is listed below.<p>"; echo "<table width=\"100%\" border=\"1\">\n"; echo "<th width=\"199\" class=\"cellheader\">Destination</th>"; echo "<th width=\"217\" class=\"cellheader\"> Cost</th>"; $querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); while ($getcity2 = $querycity2->fetchrow()) { echo "<tr>"; echo "<td width=\"199\"><a href='bus.php?act=go&id={$getcity2['City_ID']}'>{$getcity2['City_Name']}</a></td>\n"; echo "<td width=\"217\">"; echo "$getcity2[Cost]"; echo "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; include("templates/private_footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/ Share on other sites More sharing options...
Barand Posted April 19, 2008 Share Posted April 19, 2008 I would use <?php $query1 = $db->execute("update `players` set `City_ID`=?, `gold`= `gold` - ? where `id`=?", array($cityid, $buscost, $player->id)); Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-521454 Share on other sites More sharing options...
cdoyle Posted April 20, 2008 Author Share Posted April 20, 2008 Thanks, This is getting closer, Adding this, when you click on a city it removes all money the player has on hand. So it's not looking at the 'cost' field in table, it's just removing all money on hand. Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-521911 Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 Check you have the correct value in $buscost Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-521915 Share on other sites More sharing options...
cdoyle Posted April 20, 2008 Author Share Posted April 20, 2008 Check you have the correct value in $buscost I don't think it's working right. $buscost is suppose to get it's value from here $query = $db->execute("select `City_ID`, `City_Name`, `Cost` from `Cities` where `City_ID`=?", array($_GET['id'])); $buscost = $query['Cost']; I noticed if I have no money on hand, it still let's me move from city to city. It's suppose to give you a warning that you dont' have enough money. I tried to echo $buscost, but it doesn't display anything. Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-521933 Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 Don't you need a fetchrow after the execute? Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-522010 Share on other sites More sharing options...
cdoyle Posted April 20, 2008 Author Share Posted April 20, 2008 That was it!! I added the fetchrow, and now I got everything working. Thank You!!! Link to comment https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/#findComment-522072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.