GFOnyX Posted August 19, 2013 Share Posted August 19, 2013 (edited) I have the following query that gives me the result i want. In a nutshell it searches two columns to find the max value in each of these two columns and returns the sum of these two values. When i try to pass it to a variable in php it doesn't seem to work. I want to be able to pass the sum in a variable so i can use the variable later into an IF Condition. For example: if ($scoremax >= '160') { code here } Here is my query: select (max(scoreioa) + max(scoreioa2)) from result where username='username' and here is the php code: $maxscore = mysql_query("select (max(scoreioa) + max(scoreioa2)) from result where username='username'"); mysql_data_seek($maxscore, $scoremax); $row = mysql_fetch_row($maxscore); $scoremax = $row[0]; Edited August 19, 2013 by GFOnyX Quote Link to comment Share on other sites More sharing options...
.josh Posted August 19, 2013 Share Posted August 19, 2013 remove that mysql_data_seek line. Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted August 19, 2013 Author Share Posted August 19, 2013 remove that mysql_data_seek line. I did but it still doesnt seem to work. Its like the sum is not being stored in the $scoremax variable. Quote Link to comment Share on other sites More sharing options...
Solution .josh Posted August 19, 2013 Solution Share Posted August 19, 2013 dumb question.. are you sure you are properly connected to the db and all that? do this: $maxscore = mysql_query("select (max(scoreioa) + max(scoreioa2)) from result where username='username'") or die(mysql_error()); $row = mysql_fetch_row($maxscore); echo "<pre>";print_r($row); echo "</pre>"; $scoremax = $row[0]; echo $scoremax; do you get any errors displayed? what does the print_r show? what is echo'd out? is 'username' really the username? Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted August 19, 2013 Author Share Posted August 19, 2013 Yes i am propelry connected to the DB since i can already pass scores to the DB and read data from it. Sorry about the username,it was a mistake from my end.It was supposed to be $username. The result however is still that is not working. By applying the code you wrote i get this: Array( [0] => ) Quote Link to comment Share on other sites More sharing options...
.josh Posted August 19, 2013 Share Posted August 19, 2013 okay, are you sure $username has the expected value? If you run the query directly in mysql (via phpmyadmin or commandline) do you get expected results? Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted August 19, 2013 Author Share Posted August 19, 2013 .josh it seems to be working.Thank you very much. I had the code written in wrong position inside the php file. It has many lines of code already in it and i got a little lost. I tried an IF condition using the $scoremax variable and i got the results i wanted. Thanks again! BTW This site is amazing! 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.