[Ajuda] MySQL r39
#1

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.
Reply
#2

Sim, mais vai precisar criar pelo menos uma call.
Reply
#3

Vocк terб que criar uma Call.
Reply
#4

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;
}
Reply
#5

Exagerou nas strings, mas tб um exemplo bom.
Reply
#6

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

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у?
Reply
#8


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;
}
Reply
#9

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
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)