Jump to content
  • 0
Virtue

sql query question

Question

I know we have a command to get the account id, i have a question though,

 

if in any case i want to store a username, i'll have to use getcharid(3) right? so how will i query it?so that it gets save in the sql as the username not  the account id.

 

 

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

getcharid(3) returns Account ID of the user (source doc). Maybe you meant strcharinfo(0), which returns current character's name (source doc).

 

You could do something like this on your SQL:

 

.@name$ = strcharinfo(0);.@sql$ = "INSERT INTO `my_table` VALUES ('" + .@name$ + "')";query_sql(.@sql$);

 

Or, all in one sentence:

 

query_sql("INSERT INTO `my_table` VALUES ('" + strcharinfo(0) + "')");

Share this post


Link to post
Share on other sites
  • 0

yes i've checked the script_docs but to no avail, and from using the getcharid(3), I believe we can use some query to get the username not char name/id.

 

 

query_sql("SELECT `login` VALUES ('" + getcharid(3) + "') ______ userid 

 

 

im thinking something like that but i can't seem to remember what command is needed so that when you do the query you'll get the values for the userid.

Edited by Virtue

Share this post


Link to post
Share on other sites
  • 0

or maybe it would be something like

 

 

query_sql("SELECT userid FROM `login`  

then after I'm not sure what will come next

 

 

so its like, select the userid from login database using the account_id(getcharid(3))

Share this post


Link to post
Share on other sites
  • 0

If you want to retrieve the name of the current character via SQL, then this is what you should do:

 

query_sql("SELECT `name` FROM `char` WHERE `account_id` = " + getcharid(3) + " AND `online` = 1",.@name$);

Missing the online condition will lead you to retrieve all characters for that account instead of just the character's name.

 

But you could use getcharid(0) (retrieves user's char ID) and use next SQL query:

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$);

Which will guarantee you'll get your username from the SQL table.

Share this post


Link to post
Share on other sites
  • 0

haha i think im having an idea of what i have to do, although im not yet a hundred percent sure, although i meant username/userid but hey, thanks so if im correct the query should be

 

 

query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$); 

Share this post


Link to post
Share on other sites
  • 0

I don't get you. You want to get username AND userID from the database, given you've got just the account ID, without making use of the commands you're given to get them directly?

 

If not, please elaborate.

 

P.S.: looks like you want to reinvent the wheel xD

Share this post


Link to post
Share on other sites
  • 0

nope, i don't want to get the username and userid. haha. i just  used the term username/id bec. they're just the same. 

 

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); 

this one gets the name of the character right?

 

what i am looking for would be the userid, the one that we use to login,

Share this post


Link to post
Share on other sites
  • 0
query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$);

This returns UserName of the Account

 

 

nope, i don't want to get the username and userid. haha. i just  used the term username/id bec. they're just the same. 

 

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); 

this one gets the name of the character right?

 

what i am looking for would be the userid, the one that we use to login,

 

Why use a query to get Character name,

you can get character name by "strcharinfo(0)"

Share this post


Link to post
Share on other sites
  • 0

nope, i don't want to get the username and userid. haha. i just  used the term username/id bec. they're just the same. 

 

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); 

this one gets the name of the character right?

 

what i am looking for would be the userid, the one that we use to login,

 

Account name?

 

Then it's like this:

 

query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3)),.@userid$;

Share this post


Link to post
Share on other sites
  • 0

 

query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$);
This returns UserName of the Account

 

 

nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same.

 

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$);
this one gets the name of the character right?

 

what i am looking for would be the userid, the one that we use to login,

Why use a query to get Character name,

you can get character name by "strcharinfo(0)"

follow up question on this one,

input @input$;query_sql("SELECT `userid` FROM `login` WHERE `userid` = " + @input$,.@username$);
if the query did not return any value/result. should this script work like this

 

if(@input$ == .@username$){dispbottom "Value Found";}dispbottom "No Results";
hypothetically its just a sample but it should be working right?

if the input has the same value or correct value from the db it should give me "value found"

if the username that i entered is correct.

Edited by Virtue

Share this post


Link to post
Share on other sites
  • 0

 

 

query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$);
This returns UserName of the Account

 

 

nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same.

 

query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$);
this one gets the name of the character right?

 

what i am looking for would be the userid, the one that we use to login,

Why use a query to get Character name,

you can get character name by "strcharinfo(0)"

follow up question on this one,

input @input$;query_sql("SELECT `userid` FROM `login` WHERE `userid` = " + @input$,.@username$);
if the query did not return any value/result. should this script work like this

 

if(@input$ == .@username$){dispbottom "Value Found";}dispbottom "No Results";
hypothetically its just a sample but it should be working right?

if the input has the same value or correct value from the db it should give me "value found"

if the username that i entered is correct.

If the input userid exists in login table, then it will display "Value Found" Else it will display "No Results

but you forgot the else statement, 

if(@input$ == .@username$){    dispbottom "Value Found";} else {    dispbottom "No Results";}

Share this post


Link to post
Share on other sites
  • 0

o yeah, sorry. but basically what i'm thinking of is quite possible, been away for so long got super rusty that's why need to check esp when using sql queries with scripts. :D

Share this post


Link to post
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.   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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.