Jump to content

[SOLVED] My sql help


TheFreak

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.