sql query question

Virtue

New member
Messages
259
Points
0
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.

 
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:

Code:
query_sql("INSERT INTO `my_table` VALUES ('" + strcharinfo(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.

 
Last edited by a moderator:
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))

 
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.

 
Last edited by a moderator:
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

Code:
query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$); 
 
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

 
Last edited by a moderator:
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,

 
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)"

 
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:

Code:
query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3)),.@userid$;
 
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

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

 
Last edited by a moderator:
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

Code:
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, 

Code:
if(@input$ == .@username$){    dispbottom "Value Found";} else {    dispbottom "No Results";}
 
Last edited by a moderator:
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.
default_biggrin.png


 
Back
Top