Jump to content
  • 0

How to show SQL values in an NPC


Panny

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  19
  • Reputation:   0
  • Joined:  11/21/12
  • Last Seen:  

Hello, i have a SQL table called event and in there is fields called id and name.

How do i implament it into an NPC so it shows all the names stored in the 'event' database? Also maybe in Alphabetical Order?.

Example;

Name 1

Name 2

Name 3

etc

Edited by Panny
Link to comment
Share on other sites

5 answers to this question

Recommended Posts


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

.@sql = query( "SELECT `id`,`name` FROM `yourtable` ",.@id,.@name$ );
for( .@i = 0; .@i < .@sql; .@i++ )
 mes "ID : "+.@id[.@i]+" & Name : "+.@name$[.@i];

refer query_sql

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  19
  • Reputation:   0
  • Joined:  11/21/12
  • Last Seen:  

I dont want it to show the ID so would it be this?

prontera,150,83,4   script   Event Names   814{
set .@sql = query( "SELECT `name` FROM `event` ",.@name$ );
mes "[Event Names]"
for(set .@i = 0; .@i < .@sql; .@i++ )
mes "Name : "+.@name$[.@i];
close;
}

Edited by Panny
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Something like this:

prontera,150,83,4	script	Event Names	814,{
query_sql "SELECT `name` FROM `event` ORDER BY `name` ASC", .@name$;
mes "[Event Names]";
for (set .@i,0; .@i<getarraysize(.@name$); set .@i,.@i+1)
	mes "Name : " + .@name$[.@i];
close;
}

I fixed the syntax of query_sql, added ORDER BY to sort the names, and added a missing semi-colon.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  19
  • Reputation:   0
  • Joined:  11/21/12
  • Last Seen:  

Something like this:

prontera,150,83,4    script    Event Names    814,{
   query_sql "SELECT `name` FROM `event` ORDER BY `name` ASC", .@name$;
   mes "[Event Names]";
   for (set .@i,0; .@i<getarraysize(.@name$); set .@i,.@i+1)
       mes "Name : " + .@name$[.@i];
   close;
}

I fixed the syntax of query_sql, added ORDER BY to sort the names, and added a missing semi-colon.

Thanks Brian, tried your script however the NPC loads but it isnt clickable.

What may cause this?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

dunno why but if you couldn't understand Brian script ...

makes me feels like you need a little bit spoon feed already

/*
// creating table
create table event (
id int(11) primary key auto_increment,
name varchar(23),
key (name)
) engine = myisam;

// debugging script in test server
insert into event
select null, name from `char`;

// show the table
select * from event;
*/

prontera,152,179,4    script    Event Names    814,{
   query_sql "select count(1) from event", .@total;
   while (1) {
       mes "Congratulations to these players !";
       mes "Total "+ .@total +" players, Page no. "+( .@current_page +1 )+" =";
       .@nb = query_sql( "select name from event order by name limit "+ .page +" offset "+ .page * .@current_page, .@name$ );
       for ( .@i = 0; .@i < .@nb; .@i++ )
           mes .@name$[.@i];
       next;
       if ( select ( "Next Page", "Previous Page" ) == 1 ) {
           if ( .page * ( .@current_page +1 ) < .@total )
               .@current_page++;
           else {
               mes "the end of the page";
               close;
           }
       }
       else {
           if ( .@current_page )
               .@current_page--;
           else {
               mes "this is the 1st page";
               close;
           }
       }
   }
   close;
OnInit:
   .page = 2; // display 2 players per page
   end;
}

edit: forgot to index the `name` field

if you don't understand what are the commands that I've used in this script, always feel free to ask and criticize my methods

Edited by AnnieRuru
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...