xoligy Posted August 13, 2008 Share Posted August 13, 2008 ok ive more or less finished a bank script for an online game and even tho i think some of the querys are wrong they seem tp work for instance the query below works but i thought it was wrong where there is a > i thought i needed a = but with an = it dont work right $query = mysql_query("SELECT `bank_accounts`.`id`, `UserDetails`.`account_id` FROM bank_accounts, UserDetails WHERE `bank_accounts`.`id`=`UserDetails`.`account_id`"); while ($row = mysql_fetch_assoc($query)) { $get_members = mysql_query("SELECT * FROM UserDetails WHERE account_id > '$id' ORDER by banked DESC"); $num_members = mysql_num_rows($get_members); } anyway back onto the matter at hand, what ive been trying to do is make it so that a user has a choice of more than one account type at the bank, but when i change the account type in there userdetails it dont work right here is the info you'll need anyhow Table name, field names UserDetails > account_id, banked bank accounts > id, price, % , max deposit (% is the max a person cn bank with money on hand) Deposit page <? $id=$user->ID; $banked=$user->banked; $gold=$user->gold; $q="SELECT * FROM Bank where id=$id"; $r=@mysql_query($q); if ($r) { while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $fee=$row['fee']; $interest=$row['interest']; } $q="SELECT * FROM bank_accounts WHERE id=$id"; $r=@mysql_query($q); if ($r) { while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $percentage=$row['percentage']; $max=$row['max']; } $x=($percentage*$gold); if ($cgi['deposit']) { $amt = (is_numeric($cgi['deposit_amt'])) ? intval(abs($cgi['deposit_amt'])) : 0; if ($x < $amt) { $error= "<font color=red>You can't deposit more than you have</font>"; }elseif (!$cgi['deposit_amt']){ $error= "<font color=red>Please enter an amount</font>"; } else { $query = mysql_query("UPDATE UserDetails SET banked = (banked+$amt), gold = (gold-$amt) WHERE ID = '$id'"); $query = mysql_query("UPDATE Bank SET banktotal = (banktotal+$amt)"); MRedirect("bank.php"); } } if ($_POST['withdraw']) { $amt = (is_numeric($cgi['withdraw_amt'])) ? intval(abs($cgi['withdraw_amt'])) : 0; if ($banked < $amt) { $error= "<font color=red>You can't withdraw more than you have</font>"; }elseif (!$cgi['withdraw_amt']){ $error= "<font color=red>Please enter an amount</font>"; } else { $query = mysql_query("UPDATE UserDetails SET banked = ($banked-$amt), gold = ($gold + $amt) WHERE ID = '$id'"); $query = mysql_query("UPDATE Bank SET banktotal = (banktotal-$amt)"); MRedirect("bank.php"); } } ?> think thats all the info you need :/ oh if someone could explain how i would get it so a person carnt add more than what account type they have that would be appreciated! thanks for any help you can give Quote Link to comment Share on other sites More sharing options...
Dragoa Posted August 13, 2008 Share Posted August 13, 2008 Add another case in the deposit if block: } else if (($banked+$amt)>$max) { Error Here } Unless I'm missing something. Quote Link to comment Share on other sites More sharing options...
xoligy Posted August 14, 2008 Author Share Posted August 14, 2008 Thanks for that Dragoa i'll give that a shot later today and see how things go, can anyone help with the other query, of getting more than one account recognised? As it stands only account_id 1 works Quote Link to comment Share on other sites More sharing options...
Dragoa Posted August 14, 2008 Share Posted August 14, 2008 For the other one, your getting back the row of data, but your not actually doing anything with it. Your just using $id from above. Although if your still only getting 1 result, let me know and I'll try to take a better look at it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.