Why this won't work?
#1

Hi i'm using SQLite. Why this command not working? The purpose of it was to select all the strings in the 'Name' column and show on player's screen.
PHP код:
CMD:factions(playeridparams[])
{
    new 
Query[256];
    new 
DBResult:Result;
    
format(Querysizeof(Query), "SELECT 'Name' FROM `Faction`");
    
Result db_query(DatabaseQuery);
     if(
db_num_rows(Result))
      {
           new 
Field[30];
           
db_get_field_assoc(Result#Name, Field, 30);
           
printf("%s",Field);
    }
    return 
1;

EDIT:I used printf just in case to check if it appears on console or not
Reply
#2

This will literally return "Name" and store it in Field variable and not the data that are stored in that column. Use either grave accent `Name` or nothing Name.

Format is pointless in that case, just execute the query directly in db_query.

You will also need db_next_row otherwise it will only retrieve from the first row.
Reply
#3

Like this?
PHP код:
CMD:factions(playeridparams[])
{
    new 
DBResult:Result;
    
Result db_query(Database"SELECT 'Name' FROM `Faction'");
     if(
db_num_rows(Result))
      {
          do
          {
           new 
Field[30];
           
db_get_field_assoc(Result'Name'Field30);
           new 
string[120];
           
format(string,sizeof(string),"%s",Field);
           
SCM(playerid,COLOR_YELLOW,string);
        }
        while(
db_next_row(db_result));
    }
    
db_free_result(Result);
    return 
1;

Reply
#4

Fixed some errors.
PHP код:
CMD:factions(playerid)
{
    new 
DBResult:Result;
    
Result db_query(Database"SELECT 'Name' FROM `Faction`");
    if(
db_num_rows(Result))
    {
        new 
Field[30], string[100];
        
db_get_field_assoc(Result'Name'Field30);
        
format(string,sizeof(string),"%s",Field);
        
SCM(playerid,COLOR_YELLOW,string);
        while(
db_next_row(db_result));
    }
    
db_free_result(Result);
    return 
1;

Reply
#5

Thanks! Will try it and reply if it worked.EDIT: errors and i don't know these ones because i just started learning sqlite today
PHP код:
D:\Softwares\Cops And Robbers\gamemodes\Sandhu.pwn(9159) : error 027invalid character constant
D
:\Softwares\Cops And Robbers\gamemodes\Sandhu.pwn(9159) : error 017undefined symbol "ame"
D:\Softwares\Cops And Robbers\gamemodes\Sandhu.pwn(9159) : warning 215expression has no effect
D
:\Softwares\Cops And Robbers\gamemodes\Sandhu.pwn(9159) : error 001expected token";"but found "-identifier-"
D:\Softwares\Cops And Robbers\gamemodes\Sandhu.pwn(9159) : fatal error 107too many error messages on one line
Compilation aborted
.Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
4 Errors

PHP код:
db_get_field_assoc(Result'Name'Field30); 
Reply
#6

"'Name'"
Reply
#7

No, it still has issues:

- You still left it as 'Name' and explained what will return if trying to retrieve the text.
- db_result is unknown.
- do .. while loop, you forgot "do".
- The second parameter in db_get_field_assoc is a string so you'd use "Name" and not 'Name'.
- Formatting another string is again pointless.

Код:
CMD:factions(playerid, params[])
{
    new DBResult: Result = db_query(Database, "SELECT `Name` FROM `Faction");

    if (db_num_rows(Result))
    {
        new Field[30];

        do 
        {
            db_get_field_assoc(Result, "Name", Field, 30);
            // or
            // db_get_field(Result, 0, Field, 30);

            SCM(playerid, COLOR_YELLOW, Field);
        }
        while (db_next_row(Result));
    }

    db_free_result(Result);
    return 1;
}
Reply
#8

Thx! A rep to you both! So this sqlite thingy works on frag host too [Frag is linux]?
Reply
#9

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
Thx! A rep to you both! So this sqlite thingy works on frag host too [Frag is linux]?
Yes it will.
Reply
#10

And yeah one more thing can i show that Field result in a dialog style list instead of SCM?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)