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? Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/ 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 Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585119 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' Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585125 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 "==" Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585128 Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Ok,thankyou Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585129 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'"; Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585436 Share on other sites More sharing options...
fenway Posted July 9, 2008 Share Posted July 9, 2008 How about a column list? Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585518 Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Column list ? Do you mind explaining? Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585527 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" . Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585531 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. Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585578 Share on other sites More sharing options...
TheFreak Posted July 9, 2008 Author Share Posted July 9, 2008 Yeah i got my mistake...thankyou Link to comment https://forums.phpfreaks.com/topic/113863-solved-my-sql-help/#findComment-585589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.