Jump to content
  • 0

Fill array and check with IF


Question

Posted

Hi,

how can i fill a array out of a DB?  There are 5 Colum's. 

 

 

Dont work:

query_sql "SELECT `npc1`, `npc2`, `npc3`, `npc4`, `npc5` FROM `quest_db` WHERE `char_id` = " + getcharid(0) + " ", @array;
 

 

 

 

And how can i check it with "if-command", if one of the arry's have a special number.

 

This dont work...

if ( @array[1-5] == 500 OR 100 )
do this
 

 

6 answers to this question

Recommended Posts

Posted

Something like this I presume :

query_sql("SELECT `npc1`, `npc2`, `npc3`, `npc4`, `npc5` FROM `quest_db` WHERE `char_id` = " + getcharid(0), .@npc1, .@npc2, .@npc3, .@npc4, .@npc5);

for( set .@i,1; .@i<=5; set .@i, .@i + 1 ) {
    set .@var, getd(".@npc" + .@i);
    if( .@var != 500 && .@var != 100 ) {
        set .@fail, 1;
        break;
    }
}

if( .@fail ) {
    // not ok
}
else {
    // ok
}

 

Posted
query_sql "SELECT `npc1`, `npc2`, `npc3`, `npc4`, `npc5` FROM `quest_db` WHERE `char_id` = " + getcharid(0) + " ", .@npc1$,.@npc2$,.@npc3$,.@npc4$,.@npc5$;

i dun understand the array part you mentioned..

Posted

I thing i have to save this as arry because of the 5 fileds. But i can use evey field as singel variable. But how can i check if the variables are "500" or "100"? Did the "if-command" support more than one variable as argument?

Posted
if( .@npc1$ == 500 || .@npc1$ == 100 ){
    // blablbala
}

just compare the value inside the array and the value u want...

 

if you can briefly explain or tell us what you wanna do with that sql statement..perhap we can figure out another way for you....

like checking the value through SQL...

Posted

There are 5 Field's (`npc1`, `npc2`, `npc3`, `npc4`, `npc5`) in the DB.

I want to check if one of this fields have not 500 or 100 included.

 

btw: 500 and 100 are only examples for the data's.

 

Example:

 

`500`, `500`, `500`, `500`, `100` -> ok, do if

 

`500`, `500`, `500`, `500`, `400` -> not ok, do else

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