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
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
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
Share on other sites

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

 

Changed bankid to id..

 

Still dosnt work, its selecting the users current bank account again for some reason.. :S

Link to comment
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
Share on other sites

It just dosnt work.. It displays the $bank details back instead of the $newbank. asif the +1 on the id feild isnt being aplied.

 

 

I really have no idea.. So annoying.. Its gotta be the smallest script iv ever wrighten and its not working. :s

Link to comment
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
Share on other sites

Return: select * from bank where id = '1 + 1'

 

 

 

Thats correct i believe.. ID 1 is the current bank account and 1+1 = 2 which is the ID i want.

 

But the entry where ID = 2 isnt being displayed. The entry for ID 1 is being Redisplayed.

Link to comment
Share on other sites

select * from bank where id = '1 + 1'

 

what that SQL says is "select all records where id is equal to the string '1 + 1'"

 

assuming id is numeric, it will never be equal to the string '1 + 1'

 

try this:

 

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

Link to comment
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
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.