Jump to content
  • 0

Get playerName from Char ID from another SQL Table


Question

Posted

Hello community,

I'm doing a ranking for BG and it is working, however, on the SQL table "char_bg" it is just showing char_id not "name" of the character, however, I want it to show the name of the character from another table based on the char_id of the table char_bg.

Can you guys help me?

 

set .@size, query_sql( "select char_id, rank_points, division from char_bg where rank_points > 0 order by rank_points desc limit "+ .top, .@name$, .@points, .@levelname$ );
	for (set .@c, 0; .@c < .@size; set .@c, .@c + 1)
	dispbottom "[ #" +(.@c + 1) +" ]      :      " + .@name$[.@c] +"      :      " + .@levelname$[.@c] +"      :      [ " + .@points[.@c] +" ]", 0xe60000;

 

16 answers to this question

Recommended Posts

  • 0
Posted (edited)

Hello @Zell,

Thank you so much for the help! I have another question. When I try to update a column in the char_bg table, which is "Division" and I save it it can be reflected on the ranking script. But when I use a command which is @addfame 2 100 to update rank_points, the division name of the character gets deleted like if I cannot update any column manually.

 

Edited by Strand
  • 0
Posted (edited)

Here it is: I do not why I can´t update the char_bg colums manually and have them stored.

/*==========================================
 * Fame Points
 *------------------------------------------*/
ACMD_FUNC(addfame)
{
    int fame = 0, type = 0;
    nullpo_retr(-1, sd);

    if( !message || !*message || sscanf(message, "%d %d", &type, &fame) < 2 )
    {
        clif_displaymessage(fd, "Usage: @addfame <type> <points>");
        clif_displaymessage(fd, "- type : 0 Class (Alche/BS/TK) | 1 PK | 2 BG Ranked | 3 BG Regular");

        return -1;
    }

    if( type < 0 || type > 3 )
    {
        clif_displaymessage(fd, "Invalid type : 0 Class (Alche/BS/TK) | 1 PK | 2 BG Ranked | 3 BG Regular");
        return -1;
    }

    pc_addfame(sd,fame,type);
    return 0;
}

 

Edited by Emistry
codebox
  • 0
Posted

Well. Don't know if you are using some source modify or a source custom, but mine chmapif_parse_updfamelist just receive 3 types of rank. RANK_BLACKSMITH, RANK_ALCHEMIST and RANK_TAEKWON, prob yours is different.

Why not create a bindatcmd to make your query?

  • 0
Posted

@Zell Yes, I did the bindatcmd but, want I am trying to say is this:

When I manually update the colum "Division" and type in "Diamond" I click on save and it gets actually saved, like this:

image.png.f83e0326ecdf6b5889f8b6415f99b6e9.png

But, when I use the command @addfame 2 10 to add the character 10 more points, and then relog, the "Division" name for the character gets deleted.

image.png.8eb42de8ad139b30748e1570d2581043.png

image.png.016baa41cdf50280b24c2fd38222f30f.png

Do you happen to know why does it happen and how to fix it?

  • 0
Posted (edited)

@Zell, I understand. Thanks for the help!

 

By the way, since that column cannot be updated and saved, I´m thinking of creating a new column "Division" but in a different table, but, my question is: How can I do a query including another table name to search for the character Division? How can I do that? Or anything that I can add to show the Division name from another table in the Ranking List shown in the beginning of this post?

Edited by Strand
  • 0
Posted

change 

set .@size, query_sql( "select char_id, rank_points, division from char_bg where rank_points > 0 order by rank_points desc limit "+ .top, .@name$, .@points, .@levelname$ );

into

set .@size, query_sql("SELECT c.`name`, cbg.`rank_points`, cbg.`division` FROM `char_bg` cbg INNER JOIN `char` c ON c.`char_id` = cbg.`char_id` WHERE cbg.`rank_points` > 0 ORDER BY cbg.`rank_points` DESC LIMIT "+ .top, .@name$, .@points, .@levelname$);

join the `char` table to retrieve the character name.

  • 0
Posted

Hello @Emistry,

  Thanks a lot! By the way, in regards to my last question: Is there any way that I can query another table to retrieve the info from the "Division" column in the same sentence? Including the inner join to retrieve the character name.

  • 0
Posted
48 minutes ago, Strand said:

Hello @Emistry,

  Thanks a lot! By the way, in regards to my last question: Is there any way that I can query another table to retrieve the info from the "Division" column in the same sentence? Including the inner join to retrieve the character name.

Yes. Just user another inner join

INNER JOIN your_division_table div ON div.division = bg.div

  • 0
Posted
Just now, Strand said:

Hello @Zell,

I do not know how to use two INNER JOINs correctly. How would I add it considering the Emistry script?

The "Division" column is in the "char" table.

Thanks!

 

 

*coff* the scripts I posted first in pastebin it's the same query *coff*
 

Don't understand what you want. The division is only in char and not in the bg? Or in both?

  • 0
Posted

After the first INNER JOIN (I'm using mine code as reference) add

INNER JOIN `char_bg` cb ON cb.char_id = c.char_id, so you will have something like this

 "   INNER JOIN `char`     c ON c.char_id  = bg.char_id " +
"   INNER JOIN `char_bg` cb ON cb.char_id = c.char_id  " +

And now to retrieve some information of char_bg is juts use cb.COLUMN

  • 0
Posted
21 minutes ago, Strand said:

The Division is only in "char" but the other information I want to retrieve which is "points" is in "char_bg".

set .@size, query_sql("SELECT c.`name`, cbg.`rank_points`, c.`division` FROM `char_bg` cbg INNER JOIN `char` c ON c.`char_id` = cbg.`char_id` WHERE cbg.`rank_points` > 0 ORDER BY cbg.`rank_points` DESC LIMIT "+ .top, .@name$, .@points, .@levelname$);

 

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