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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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