SA-MP Forums Archive
[Ajuda] MySQL r39 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] MySQL r39 (/showthread.php?tid=542319)



MySQL r39 - Stronda xD - 18.10.2014

Queria saber se tem como eu pegar todas essas linhas em uma consulta sу, sem ter que criar uma Call para todas as linhas separadamente.



Re: MySQL r39 - RiqueP - 18.10.2014

Sim, mais vai precisar criar pelo menos uma call.


Re: MySQL r39 - ipsLuan - 18.10.2014

Vocк terб que criar uma Call.


Re: MySQL r39 - RiqueP - 18.10.2014

eu criei um cуdigo bem rapidinho aqui pra dar de exemplo
pawn Код:
new query[1024];
format(query, sizeof(query), "SELECT * FROM `tabela` WHERE `id` = '%d'", 1);
mysql_function_query(connect, query, true, "Call", "");

forward Call();
public Call()
{
    new linhas, campos;
    cache_get_data(linhas, campos, connect);
    if(linhas)
    {
        new query[1024], string[128];
        cache_get_field_content(0, "mapname", query, connect);
        format(string, 128, "mapname %s", query);
        SendRconCommand(string);
    }
    return 1;
}



Re: MySQL r39 - ipsLuan - 18.10.2014

Exagerou nas strings, mas tб um exemplo bom.


Re: MySQL r39 - RiqueP - 18.10.2014

Sim, sempre exagero no MySQL pois uso consultas muito longas =)


Re: MySQL r39 - Stronda xD - 18.10.2014

Quote:
Originally Posted by RiqueP
Посмотреть сообщение
eu criei um cуdigo bem rapidinho aqui pra dar de exemplo
pawn Код:
new query[1024];
format(query, sizeof(query), "SELECT * FROM `tabela` WHERE `id` = '%d'", 1);
mysql_function_query(connect, query, true, "Call", "");

forward Call();
public Call()
{
    new linhas, campos;
    cache_get_data(linhas, campos, connect);
    if(linhas)
    {
        new query[1024], string[128];
        cache_get_field_content(0, "mapname", query, connect);
        format(string, 128, "mapname %s", query);
        SendRconCommand(string);
    }
    return 1;
}
Mas tipo, nгo teria como pegar tudo de uma vez? mapname, hostname, gamemodetext e talz em uma Call sу?


Re: MySQL r39 - Deeh16 - 18.10.2014


pawn Код:
public OnGameModeInit() {
    for(new y = 0; y <= 4; y++){
        mysql_format(conexгo,string,sizeof(string),"SELECT * FROM `nometabela` WHERE `id` = '%i'",y);
        mysql_tquery(conexгo, string, "Nome_Callback", "");
    }
    return true;
}
forward Nome_CallBack();
public Nome_CallBack(){
    new rows,fields;
    cache_get_data(rows, fields);
    if(cache_num_rows() == 1){
        new x1[130],y2[130],z3[130];
        cache_get_field_content(0, "configuracao-key", x1);
        cache_get_field_content(0, "configuracao-Valor", y2);
        cache_get_field_content(0, "UltimaAlteracao", z3);
        printf("Configuraзгo Key = %s Configuraзгo Valor = %s Ultima Alteraзгo = %s",x1,y2,z3);
}
    return true;
}



Re: MySQL r39 - RiqueP - 18.10.2014

pawn Код:
new query[1024];
format(query, sizeof(query), "SELECT * FROM `tabela` WHERE `id` = '%d'", 1);
mysql_function_query(connect, query, true, "Call", "");

forward Call();
public Call()
{
    new linhas, campos;
    cache_get_data(linhas, campos, connect);
    if(linhas)
    {
        new query[1024], string[128];
        cache_get_field_content(0, "mapname", query, connect);
        format(string, 128, "mapname %s", query);
        SendRconCommand(string);
       
        cache_get_field_content(0, "hostname", query, connect);
        format(string, 128, "hostname %s", query);
        SendRconCommand(string);
       
        cache_get_field_content(0, "weburl", query, connect);
        format(string, 128, "weburl %s", query);
        SendRconCommand(string);
       
        cache_get_field_content(0, "gamemodetext", query, connect);
        format(string, 128, "gamemodetext %s", query);
        SendRconCommand(string);
    }
    return 1;
}
devo avisar que o id 1 deve existir, jб que a consulta vai procura-lo.

@EDIT

dependendo da versгo do seu MySQL vocк usa meu cуdigo de exemplo ou do Deeh16


Re: MySQL r39 - PT - 18.10.2014

O id e sempre diferente se reparar aconselho a recriar essa tabela e utilizar isso apenas numa row.