Help about mysql function
#1

I am starded working on my faction system that runs on BlueG's mysql plugin.
I just don't know how to create /makefaction command, to be more precise, how to check if
there is available ID in table "FACTIONS" and use that id for faction I created.
I also tried to convert this plugin in Mysql 40+ from BueG's but I also have problem with making command.
https://sampforum.blast.hk/showthread.php?tid=606469
So, if someone can just igve me the basic example for /makeorg command with BlueG's mysql plugin i would appriciate that.
Reply
#2

May you please link down the codes you used aswell as the screenshot of your phpmyadmin
Reply
#3

When player uses /makefaction [name][type]

PHP код:
stock CreateFaction(fname[], Float:PlayerPosXFloat:PlayerPosYFloat:PlayerPosZftype)
{
    
DB::CreateRow(FactionTable"FactionName"fname);
 
    new 
yearmonthday;
 
    
getdate(yearmonthday);
 
    new 
fcID GetAvailableFactionID();
 
    
FactionInfo[fcID][dbID] = ReturnLastKey();
    
FactionInfo[fcID][fID] = fcID;
 
    
FactionInfo[fcID][fType] = ftype;
    
FactionInfo[fcID][fX] = PlayerPosX;
    
FactionInfo[fcID][fY] = PlayerPosY;
    
FactionInfo[fcID][fZ] = PlayerPosZ;
 
    new 
cdate[30];
    
format(cdatesizeof cdate"%02d/%02d/%d"daymonthyear);
 
    
DB::SetLastIntEntry(FactionTable"fType"ftype"Reference");
    
DB::SetLastFloatEntry(FactionTable"LockerX"PlayerPosX"Reference");
    
DB::SetLastFloatEntry(FactionTable"LockerY"PlayerPosY"Reference");
    
DB::SetLastFloatEntry(FactionTable"LockerZ"PlayerPosZ"Reference");
    
DB::SetLastStringEntry(FactionTable"CreationDate"cdate"Reference");
 
    
LoadFactions();
 
    
#if defined DEBUG_MODE
        
printf("[FACTION CREATION] %s has been created today (%s). [IG ID: %d | SQL ID: %d]"fnamecdatefcIDFactionInfo[fcID][dbID]);
    
#endif
    
return 1;

GetAvailableFactionID(); from stock above

PHP код:
stock GetAvailableFactionID()
{
    new 
id;
    for(new 
iMAX_FACTIONSi++)
    {
        if(
FactionInfo[i][dbID] == 0)
        {
            
id i;
            break;
        }
    }
    return 
id;

and returnlastkey

PHP код:
stock ReturnLastKey()
{
    return 
DB::GetRowsPoolSize(FactionTable);

I need this to be converted to BlueG's Mysql plugin 40+
Reply
#4

Quote:
Originally Posted by masuzaron
Посмотреть сообщение
I just don't know how to create /makefaction command, to be more precise, how to check if
there is available ID in table "FACTIONS" and use that id for faction I created.
SQL has nice options called autoincrement and primary key.
You can set these as fieldname ID for example.
Take a look at this query to create a table:

Код:
CREATE TABLE Persons (
    ID int NOT NULL AUTO_INCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID)
);
The field ID in the table Persons was created as auto_increment and "PRIMARY KEY (ID)" makes this field a primary key.
This feature allows you to have an unique ID for each row in the database and you are not required to count it scriptwise.
For example when there are 4 rows in the table with id 1,2,3 and 4, SQL automatically created ID 5 at the next row and 6 for the one after that and go on..

All you have to do in your query is putt "null" as ID and SQL will do the rest for you:

PHP код:
format(Querysizeof(Query), "INSERT INTO `Persons` (`ID`, `LastName`, `FirstName`, `Age`) VALUES(NULL,'%s', '%s', '%d')"LastNameVar[playerid], FirstNameVar[playerid], AgeVar[playerid]); 
Reply
#5

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
SQL has nice options called autoincrement and primary key.
You can set these as fieldname ID for example.
Take a look at this query to create a table:

Код:
CREATE TABLE Persons (
    ID int NOT NULL AUTO_INCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID)
);
The field ID in the table Persons was created as auto_increment and "PRIMARY KEY (ID)" makes this field a primary key.
This feature allows you to have an unique ID for each row in the database and you are not required to count it scriptwise.
For example when there are 4 rows in the table with id 1,2,3 and 4, SQL automatically created ID 5 at the next row and 6 for the one after that and go on..

All you have to do in your query is putt "null" as ID and SQL will do the rest for you:

PHP код:
format(Querysizeof(Query), "INSERT INTO `Persons` (`ID`, `LastName`, `FirstName`, `Age`) VALUES(NULL,'%s', '%s', '%d')"LastNameVar[playerid], FirstNameVar[playerid], AgeVar[playerid]); 
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)