MySQL Question important.
#1

I have a cellphone system so I decided to make a mailbox.
my question is if the code is good to use, and not taking to much memory.
this is my code:

pawn Код:
#define MAX_PLAYER_SMS 5

enum SMS_INFO
{
    smsID,
    smsOwner[256],
    smsInfo[256],
    smsFrom,
    smsOn,
}
new SmsInfo[MAX_PLAYER_SMS][MAX_PLAYERS][SMS_INFO];

CMD:smsbox(playerid, params[])
{
    new query[256];
    format(query, sizeof(query), "SELECT * FROM `smslog` WHERE `name` = '%s'", GetName(playerid));
    mysql_function_query(dbHandle, query, true, "DisplaySMSLog", "i", playerid);
    return 1;
}

CMD:deletesms(playerid, params[])
{
    new query[256], smsslot;
    if(sscanf(params,"d",smsslot)) return SyntaxMSG(playerid, "/deletesms [sms-slot] (/smsbox)");
    if(!SmsInfo[smsslot][playerid][smsOn]) return SCM(playerid, -1, "Invalid SMS slot id.");
    format(query, sizeof(query), "DELETE FROM `smslog` WHERE `id` = %d", SmsInfo[smsslot][playerid][smsID]);
    mysql_function_query(dbHandle, query, true, "OnPlayerDeleteSMS", "ii", playerid, smsslot);
    return 1;
}

forward OnPlayerDeleteSMS(playerid, smsslot);
public OnPlayerDeleteSMS(playerid, smsslot)
{
    SmsInfo[smsslot][playerid][smsOn] = 0;
    return 1;
}

forward DisplaySMSLog(playerid);
public DisplaySMSLog(playerid)
{
    new rows, fields, str[256], temp[128], total = 0;
    cache_get_data(rows, fields);
    if(!rows) return SCM(playerid, COLOR_YELLOWG, "You have no SMS's in your smsbox.");
    while(total < rows)
    {
        cache_get_row(total, 0, temp), SmsInfo[total][playerid][smsID] = strval(temp);
        cache_get_row(total, 1, SmsInfo[total][playerid][smsOwner]);
        cache_get_row(total, 2, temp), SmsInfo[total][playerid][smsFrom] = strval(temp);
        cache_get_row(total, 3, SmsInfo[total][playerid][smsInfo]);
        SmsInfo[total][playerid][smsOn] = 1;
        format(str, sizeof(str), "SMS %d: from %d, %s.", total, SmsInfo[total][playerid][smsFrom], SmsInfo[total][playerid][smsInfo]);
        SCM(playerid, COLOR_YELLOWG, str);
        total++;
    }
    return 1;
}

stock AddSMSToMySQL(playerid, fromnumber, info[])
{
    new Query[500];
    format(Query, sizeof(Query), "INSERT INTO `smslog` (name, fromnumber, info) VALUES('%s', %d, '%s')",GetName(playerid), fromnumber, info);
    mysql_function_query(dbHandle, Query, true, "", "");
    return 1;
}
Reply


Messages In This Thread
MySQL Question important. - by PaulDinam - 25.02.2013, 00:56
Re: MySQL Question important. - by Scenario - 25.02.2013, 01:29
Re: MySQL Question important. - by PaulDinam - 25.02.2013, 01:40
Re: MySQL Question important. - by thefatshizms - 25.02.2013, 02:04
Re: MySQL Question important. - by Vince - 25.02.2013, 05:11
Re: MySQL Question important. - by PaulDinam - 25.02.2013, 10:17
Re: MySQL Question important. - by PaulDinam - 25.02.2013, 12:15
Re: MySQL Question important. - by PaulDinam - 25.02.2013, 14:15
Re: MySQL Question important. - by Scenario - 25.02.2013, 16:09

Forum Jump:


Users browsing this thread: 1 Guest(s)