Jump to content
  • 0

Need help with this query_sql


PewN

Question


  • Group:  Members
  • Topic Count:  209
  • Topics Per Day:  0.05
  • Content Count:  892
  • Reputation:   27
  • Joined:  12/09/11
  • Last Seen:  

I'm having a problem with my script on query_sql

set .@nb, query_sql("select char_id, win, lost from char_bg order by win desc limit 10", .@char_id, .@win, .@lost);
mes "^0000FF[ BG Ranking ]^000000";
for ( set .@i, .@j; .@i < 10; set .@i, .@i + 1 ) {
query_sql "select name from `char` where char_id = "+.@char_id[.@i], .@name$;
mes "^0000FF"+ (.@i+1) +": ^006699"+ ( (.@name$[.@i] == "")? "None":.@name$[.@i]) +"^000000 ^00AA00W["+ .@win[.@i] +"]^000000 ^FF0000L["+ .@lost[.@i] +"]^000000";
}
Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

	set .@nb, query_sql( "select char_id as aaa, ( select name from `char` where char_id = aaa ), win, lost from char_bg order by win desc limit 10", .@char_id, .@name$, .@win, .@lost );

mes "^0000FF[ BG Ranking ]^000000";

for ( set .@i, 0; .@i < .@nb; set .@i, .@i +1 )

mes "^0000FF"+ (.@i+1) +": ^006699"+ ( ( getstrlen( .@name$[.@i] ) )? .@name$[.@i] : "None" ) +"^000000 ^00AA00W["+ .@win[.@i] +"]^000000 ^FF0000L["+ .@lost[.@i] +"]^000000";

Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  209
  • Topics Per Day:  0.05
  • Content Count:  892
  • Reputation:   27
  • Joined:  12/09/11
  • Last Seen:  

	set .@nb, query_sql( "select char_id as aaa, ( select name from `char` where char_id = aaa ), win, lost from char_bg order by win desc limit 10", .@char_id, .@name$, .@win, .@lost );
	mes "^0000FF[ BG Ranking ]^000000";
	for ( set .@i, 0; .@i < .@nb; set .@i, .@i +1 )
		mes "^0000FF"+ (.@i+1) +": ^006699"+ ( ( getstrlen( .@name$[.@i] ) )? .@name$[.@i] : "None" ) +"^000000 ^00AA00W["+ .@win[.@i] +"]^000000 ^FF0000L["+ .@lost[.@i] +"]^000000";

i will try this thank you very much annieruru

i didn't know that query_sql can do like this  :(

 

query_sql("select char_id as aaa, ( select name from `char` where char_id = aaa), win, lost from char_bg order by win desc limit 10", .@char_id, .@name$, .@win, .@lost );
Edited by TrojanWorm
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

http://rathena.org/board/topic/73169-player-checker-npc/?p=150668
http://www.eathena.ws/board/index.php?showtopic=268999

actually if you have indexed the `char_id` column in `char_bg` table, you can actually do a JOIN statement





set .@nb, query_sql( "select `char`.name, char_bg.win, char_bg.lost from char_bg left join on `char` where `char`.char_id = char_bg.char_id order by char_bg.win desc limit 10", .@name$, .@win, .@lost );

I just prefer to do like that because I don't need to remember or look for the table has been indexed properly or not
so if you didn't indexed that table, my syntax will perform the search faster than this join ones

in your case, the `win` column from `char_bg` table should be indexed

Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  209
  • Topics Per Day:  0.05
  • Content Count:  892
  • Reputation:   27
  • Joined:  12/09/11
  • Last Seen:  

thanks for the info annie ruru ~

Link to comment
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

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