Jump to content

Mysql query help


xoligy

Recommended Posts

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 :D

 

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.