Jump to content
  • 0

Need help with this query_sql


Question

Posted

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";
}

4 answers to this question

Recommended Posts

Posted (edited)

	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
Posted (edited)
	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
Posted (edited)

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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...