Necesito ayuda con esto -
The_Scope - 30.05.2013
Hola amigos, tengo lo siguiente:
pawn Код:
stock CargarServers()
{
new query[300], string[128];
for(new i=1; i < MAXSERVERS; i++)
{
format(query, sizeof(query), "SELECT * FROM servers WHERE id='%i'", i);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(string, "id"); ServersInfo[i][id] = strval(string);
mysql_fetch_field_row(string, "servername"); ServersInfo[i][servername] = strlen(string);
mysql_fetch_field_row(string, "adminserver"); ServersInfo[i][adminserver] = strval(string);
mysql_fetch_field_row(string, "servermap"); ServersInfo[i][servermap] = strval(string);
mysql_fetch_field_row(string, "serverstatus"); ServersInfo[i][serverstatus] = strlen(string);
servidores++;
}
}
printf("[BFS Info]: %i Servidores cargados.", servidores);
}
Carga todo perfecto menos
ServersInfo[i][servername] = strlen(string); y
ServersInfo[i][serverstatus] = strlen(string);. Esos dos son palabras por eso puse
strlen, y todos los demбs son nъmeros, por eso puse
strval. Pero igual sigue sin cargar las palabras
Si alguien sabe que estoy haciendo mal estarнa agradecido
Respuesta: Necesito ayuda con esto -
Jovazxc - 30.05.2013
strlen retorna en numeros la longitud de la cadena, por lo que strlen no te sirve, tienes que usar algo para copiar cadenas, puedes usar format o strcat, pero en este caso es mas sencillo con strcat
pawn Код:
stock CargarServers()
{
new query[300], string[128];
for(new i=1; i < MAXSERVERS; i++)
{
format(query, sizeof(query), "SELECT * FROM servers WHERE id='%i'", i);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(string, "id"); ServersInfo[i][id] = strval(string);
mysql_fetch_field_row(string, "servername"); strcat(ServersInfo[i][servername], string);
mysql_fetch_field_row(string, "adminserver"); ServersInfo[i][adminserver] = strval(string);
mysql_fetch_field_row(string, "servermap"); ServersInfo[i][servermap] = strval(string);
mysql_fetch_field_row(string, "serverstatus"); strcat(ServersInfo[i][serverstatus], string);
servidores++;
}
}
printf("[BFS Info]: %i Servidores cargados.", servidores);
}
NOTA: strcat no es para copiar exactamente, si no que es para concatenar, si tienes duda revisa esto:
https://sampwiki.blast.hk/wiki/Strcat
Respuesta: Necesito ayuda con esto -
The_Scope - 30.05.2013
Gracias por responder Josstaa, lo he probado pero sigue sin funcionar :S. Tambien hice asi:
pawn Код:
stock CargarServers()
{
new query[300], string[128];
for(new i=1; i < MAXSERVERS; i++)
{
format(query, sizeof(query), "SELECT * FROM servers WHERE id='%i'", i);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(string, "id"); ServersInfo[i][id] = strval(string);
mysql_fetch_field_row(string, "servername"); format(ServersInfo[i][servername],40,string);
mysql_fetch_field_row(string, "adminserver"); ServersInfo[i][adminserver] = strval(string);
mysql_fetch_field_row(string, "servermap"); ServersInfo[i][servermap] = strval(string);
mysql_fetch_field_row(string, "serverstatus"); format(ServersInfo[i][serverstatus],8,string);
servidores++;
}
}
printf("[BFS Info]: %i Servidores cargados.", servidores);
}
Pero sigue sin funcionar, no se que sera
Respuesta: Necesito ayuda con esto -
DesingMyCry - 30.05.2013
pawn Код:
stock CargarServers()
{
new query[300], string[128];
for(new i=1; i < MAXSERVERS; i++)
{
format(query, sizeof(query), "SELECT * FROM servers WHERE id='%i'", i);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(string, "id"); ServersInfo[i][id] = strval(string);
mysql_fetch_field_row(string, "servername"); format(ServersInfo[i][servername],40,string);
mysql_fetch_field_row(string, "adminserver"); ServersInfo[i][adminserver] = strval(string);
mysql_fetch_field_row(string, "servermap"); ServersInfo[i][servermap] = strval(string);
mysql_fetch_field_row(string, "serverstatus"); format(ServersInfo[i][serverstatus],8,string);
servidores++;
}
}
printf("[BFS Info]: %i Servidores cargados.", servidores);
}
Estas ocupando espacio de memoria realmente para nada. Me pregunto, para que haces esto.
Si lo que almacenarб esa variable no son mas de "37+MAXIMO TAMAСO DE 'i'"? eso hace que el proceso sea mas lento (velocidad) y que ocupes memoria RAM sin alguna razуn.
Lo correcto serнa.
pawn Код:
new query[38+9]; //Uno mas por el carбcter nulo.
Puedes leer mas sobre esto, aquн.
https://sampforum.blast.hk/showthread.php?tid=170427
Ahora tu segundo problema.
pawn Код:
mysql_fetch_field_row(string, "servername"); format(ServersInfo[i][servername],40,string);
Porque usar un "format" si puedes usar directamente la variable.
pawn Код:
mysql_fetch_field_row(ServersInfo[i][servername], "servername");
Respuesta: Necesito ayuda con esto -
JustBored - 30.05.2013
Usa cache_get_field_cotent es mucho mбs prбctico.
Respuesta: Necesito ayuda con esto -
The_Scope - 31.05.2013
Muchas gracias a todos, ya lo resolvi.
PD: Gracias DesingMyCry, arreglare eso.