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
https://forums.phpfreaks.com/topic/119461-mysql-query-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.