Jump to content
  • 0

sql query that counts/checks how many key are already inserted


iZeal

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   2
  • Joined:  06/09/14
  • Last Seen:  

Hello Guys, I'm trying to modify a script for max level reward

but I'm stuck on sql query.

regarding checking if how many key entry are already inside acc_reg_num_db

like for example it will check if there is already 50 entry of #99reward

 

 

 

Thanks in advance.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

SQL has a 'COUNT()' function: http://www.w3schools.com/sql/sql_func_count.asp

Though I suggest you just keep a global variable instead (and sync it with SQL if necessary once when the server starts), since there's no point running the query repeatedly--that'd be much slower than checking a global.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   2
  • Joined:  06/09/14
  • Last Seen:  

I'm doing this for my race to lvl 99 reward because it's only for 1 claim per account., and it's only meant for 100 players else if 100 players already claimed the npc will hide. that's why I'm using #99reward because I restrict for account.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

So use a global variable ($var) to keep track of how many players have gotten the reward, i.e. increment it every time you give one. Much simpler than counting database entries.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   2
  • Joined:  06/09/14
  • Last Seen:  

if i use that maybe it will not be 1 per account.?

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  153
  • Topics Per Day:  0.04
  • Content Count:  2285
  • Reputation:   745
  • Joined:  06/16/12
  • Last Seen:  

if i use that maybe it will not be 1 per account.?

 

$ <- global var

# <- account var

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

sth like this

	if ( #reward_account ) {
		mes "already claimed";
		close;
	}
	getitem ...
	$total_claimed++;
	if ( $total_claimed > 100 ) disablenpc
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...