Monk3h Posted April 26, 2008 Share Posted April 26, 2008 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!"; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 26, 2008 Share Posted April 26, 2008 $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. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 Still wont accept :S eg, if my current account is id 1 it wont select id 2 as the newbank. It dosnt select anything and dosnr bring back a value. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 26, 2008 Share Posted April 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 $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 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 26, 2008 Share Posted April 26, 2008 Change: {$bank['id']} + 1 To: {$bank['id'] + 1} Try that. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 26, 2008 Share Posted April 26, 2008 Try running the query in the MySQL client, and make sure you have OR die(mysql_error()); at the end of the mysql_query line. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 what you put should work.. But it dosnt. :s Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 26, 2008 Share Posted April 26, 2008 Does MySQL issue an error or is there just no results? Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 echo your SQL and see what it looks like. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 i echos the result if thats what you mean. It reads back Resource id #10 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 i mean echo out the SQL that you are executing with mysql_query($sql) look at the value of $sql inside mysql_query() what does your SQL SELECT statement look like? Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 $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]); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 update to this: $query = "select * from bank where id = '{$bank['id']} + 1'"; echo $query; Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 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)."'"; Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 26, 2008 Author Share Posted April 26, 2008 Works now.. Thanks dude! Could you briefly explain to me what the difference is beetween the 2? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 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. 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.