Jump to content
  • 0

Fill array and check with IF


Vincent

Question


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

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
 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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
}

 

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2346
  • Joined:  10/28/11
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

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?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2346
  • Joined:  10/28/11
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

seem good. Will be tested...

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

×
×
  • Create New...