TheFreak Posted July 9, 2008 Share Posted July 9, 2008 Hey i need a query to list users having some field (suppose "rank" of a player) in a way that it shows "+" or "-" 5 rank to the user who queries it. Suppose i have a rank 45 in certain game,so i am asking if there is any mysql query thatll automatically shows me list of users in between 40 to 50 rank i.e "+" and "-" 5 to my rank( i.e 45) or do i have to code it in php? Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 9, 2008 Share Posted July 9, 2008 Just create 2 temporary variables, like $hi and $low. and whatever the middle value is(the value between the +/-5) add or subtract 5 frm it and put it in its respective variable(for example, if you want 40, $low would get 40 - 5 = 35). Then just do a "SELECT FROM table WHERE column > '$low' AND column < '$hi' " thats pretty much it Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Ah so you mean there is a mysql query SELECT FROM table WHERE column > '$low' AND column < '$hi' Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 9, 2008 Share Posted July 9, 2008 yes, that is correct. All basic operators(==, >, <, !=, etc) are usable in mysql. Actually, thats slightly wrong, because mysql uses "=" to compare, not "==" Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Ok,thankyou Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Well i tried again and its giving me error Could not get list address:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM battle_users WHERE rank > '0' AND rank < ''' at line 1 Heres the mysql am using $list ="SELECT FROM battle_users WHERE rank > '$low' AND rank < '$hi'"; Quote Link to comment Share on other sites More sharing options...
fenway Posted July 9, 2008 Share Posted July 9, 2008 How about a column list? Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Column list ? Do you mind explaining? Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Well here is my code print "<br>Chatacter's Name <br><td>Rank</td><br><td>Action</td>"; //Getting the rank of the user logged in $getaddress="SELECT * FROM battle_users WHERE cname ='$_SESSION[cname]'"; $getaddress2=mysql_query($getaddress) or die("Could not get address"); $getaddress3=mysql_fetch_array($getaddress2); //Getting the list of users having rank +/- 5 than the logged in user by setting high and low. $high=$getaddress3['rank']+5; $low=$getaddress3['rank']-5; $list="SELECT FROM battle_users WHERE rank BETWEEN '$low' AND '$high'"; $list2=mysql_query($list) or die("Could not get list address"); while($list3=mysql_fetch_array($list2)) { print "<tr class='mainrow'><td><a href='profileform.php?ID=$list3[cname]'>$list3[cname]</a></td><td>$list3[rank]</td><td>Challenge User</td></tr>"; } I am trying to list the users having "rank" +/- 5 than the rank of the person logged in."rank" is just a column in mysql.But i am getting the error message "Could not get list address" . Quote Link to comment Share on other sites More sharing options...
fenway Posted July 9, 2008 Share Posted July 9, 2008 I don't need to see you code -- compare $getaddress with $list and you'll see what I mean. Quote Link to comment Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Yeah i got my mistake...thankyou 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.