MySQL increase
#1

Okay I want to make /createdrugs cmd and it is creating it and everything.
PHP код:
CMD:createdrugs(playerid)
{
    if(
PlayerInfo[playerid][Admin] < 5)
    {
        
ERROR(playerid"You are not allowed to use that command");
        return 
1;
    }
    new 
Float:XFloat:YFloat:Zplacequery[128];
    
GetPlayerPos(playeridXYZ);
    
DrugsPickup[place] = CreateDynamicPickup(12791XYZ);
    
DrugsLabel[place] = CreateDynamic3DTextLabel(""SERVERBLUE"[ DRUGS ]\n"WHITE"To buy drugs type /buydrugs"0x1D9F00AAXYZ,  10.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -120.0);
    
DrugsInfo[place][ID] = cache_insert_id();
    
DrugsInfo[place][dPosX] = X;
    
DrugsInfo[place][dPosY] = Y;
    
DrugsInfo[place][dPosZ] = Z;
    
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `drugs` (`ID`, `X`, `Y`, `Z`) VALUES (%d, %f, %f, %f)"cache_insert_id(), XYZ);
    
mysql_tquery(g_SQLquery);
    return 
1;

How can I make that Id increase everytime I type command. Table ID has Auto-Increasment..

Don't laught to me I am begginer
Reply
#2

You specify a callback in mysql_tquery and call cache_insert_id() in there.
Reply
#3

I did it like this
PHP код:
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `drugs` (`X`, `Y`, `Z`) VALUES (%d, %f, %f, %f)"XYZ);
    
mysql_tquery(g_SQLquery"CreatePickupA");

forward CreatePickupA(place);
public 
CreatePickupA(place)
{
    
DrugsInfo[place][ID] = cache_insert_id();
    return 
1;

And housl tquery go like this??
Reply
#4

Okay I did that and it is saving. But problem is that every ID is 0.. any fix?
Reply
#5

PHP код:
mysql_tquery(g_SQLquery"CreatePickupA""i"place); 
Reply
#6

I did this
PHP код:
Iter_Add(i_Drugsid);
     
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `drugs` (`X`, `Y`, `Z`) VALUES (%f, %f, %f)"XYZ);
    
mysql_tquery(g_SQLquery"CreatePickupA""d"id); 
Still the same. ID is 0 for every pickup
Reply
#7

PHP код:
CMD:createdrugs(playerid

    if(
PlayerInfo[playerid][Admin] < 5
    { 
        
ERROR(playerid"You are not allowed to use that command"); 
        return 
1
    }
    new 
Float:XFloat:YFloat:Zquery[128]; 
    
GetPlayerPos(playeridXYZ); 
    new 
id Iter_Free(i_Drugs);
    
DrugsPickup[id] = CreateDynamicPickup(12791XYZ); 
    
DrugsLabel[id] = CreateDynamic3DTextLabel(""SERVERBLUE"[ DRUGS ]\n"WHITE"To buy drugs type /buydrugs"0x1D9F00AAXYZ,  10.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -120.0); 
    
DrugsInfo[id][dPosX] = X
    
DrugsInfo[id][dPosY] = Y
    
DrugsInfo[id][dPosZ] = Z;
    
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `drugs` (`X`, `Y`, `Z`) VALUES (%f, %f, %f)"XYZ); 
    
mysql_tquery(g_SQLquery"CreatePickupA""i"id);
    return 
1
}  
forward CreatePickupA(id);
public 
CreatePickupA(id)
{
    
DrugsInfo[id][ID] = cache_insert_id();
    
Iter_Add(i_Drugsid);
    return 
1;

Reply
#8

Okay there is problem. It won't let me check Auto-Increasment box.
It gives me this

Incorrect table definition; there can be only one auto column and it must be defined as a key

EDIT: FIXED!!!
Thank you all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)