Jump to content

Noob Question


Monk3h

Recommended Posts

why dosnt the $newbank work?

 

thee is a feild in the Players table called bankaccount, im using that to define what bank account they have. This referances to the table bank where all the bank account details are kept. What i dont understand is why dosnt the Select from bank where id = id +1 work to select the next bank account up. :S

 

 

$bankaccount = ($stat[bankaccount]);
$bank = mysql_fetch_array(mysql_query("select * from bank where name='$bankaccount'"));
$newbank = mysql_fetch_array(mysql_query("select * from bank where '$bank[id]' = '$bank[id]' + 1"));



$bankmin = ($newbank[min] - $stat[bank]);
$interestinc = ($newbank[interest] - $bank[interest]);


Print "<br><br><br>You are currently using our <b>$bankaccount</b> offer, which gives you a huge <b>$bank[interest]</b>% Interest a day<br><br><br>";


Print "However with a minimum deposite of <b>$bankmin</b> on top of your current ballance you can upgrade to a <b>$newbank[name]</b> Account<br><br> This account offers a daily interest rate of <b>$newbank[interest]</b>%. Thats an increase of <b>$interestinc</b>% a Day!";

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/
Share on other sites

$newbank = mysql_fetch_array(mysql_query("select * from bank where '{$bank[id]}' = '{$bank[id]}' + 1"));

 

You MUST enclose arrays in brackets if you are putting them in a string.  And you should really separate the mysql_fetch_array and mysql_query lines.  Easier to work with later.

 

 

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/#findComment-527821
Share on other sites

Do this:

$query = "select * from bank where bankid = '{$bank['id']} + 1'";
$result = mysql_query($query) OR die (mysql_error());
$newbank = mysql_fetch_array($result);

 

Assuming that bankid is the column with the bank ID.  Don't know why you had WHERE $bank[id] = $bank[id] +1, because that'll NEVER be true.  That's like WHERE 4 = 5.  You need to use the column name.

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/#findComment-527832
Share on other sites

Parse error: syntax error, unexpected '+', expecting '}' in /home/monk3h/public_html/bank.php on line 50

 

 

 

I'm prety sure its not working because its setup wrong.

 

To get the newbank id i need to select from bank where name = $stat[bankaccount]

 

once that is selected i need to select the bank account with an id higher than that one by 1.

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/#findComment-527839
Share on other sites

$bankaccount = ($stat[bankaccount]);
$bank = mysql_fetch_array(mysql_query("select * from bank where name='$bankaccount'"));
$query = "select * from bank where id = '{$bank['id']} + 1'";
$result = mysql_query($query) OR die (mysql_error());
$newbank = mysql_fetch_array($result);

$bankmin = ($newbank[min] - $stat[bank]);
$interestinc = ($newbank[interest] - $bank[interest]);

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/#findComment-527899
Share on other sites

it comes down to quoting an arithmetical expression in a SQL statement. anything in quotes is taken literally, so no math will work in there. the other alternative was to remove the quotes from your original statement and MySQL would do the math, but it's better to do the math in PHP and send a quoted string to MySQL.

 

should also work without quotes:

 

$query = "select * from bank where id = ({$bank['id']} + 1)";

 

... but then we have an unquoted comparison value in the SQL, which should be avoided.

 

Link to comment
https://forums.phpfreaks.com/topic/103047-noob-question/#findComment-527909
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.