Jump to content

[REZOLVAT] Select * FROM


Jakewow
 Share

Recommended Posts

Salut

 

Deci am in DB un tabel numit 'urati' in care am coloanele `id` `NUME` `IDJOC`

 

In acel tabel se stocheaza niste useri

 

Eu vreau sa fac o comanda spre exemplu /showurati in care sa-mi arate prin SCM toti userii stocati in acel tabel

 

Ce am reusit eu pana acum :

CMD:uratii(playerid, params[]) {
	if(PlayerInfo[playerid][pAdmin] <= 4) return SCM(playerid, -1, "");
	new query[128];
	format(query, sizeof(query), "SELECT * FROM `urati`");
	new Cache: result, id, nick, idjoc, szResult[256];
	result = mysql_query(SQL, query);
	cache_get_field_content(0, "id", szResult); id = strval(szResult);
	cache_get_field_content(0, "NUME", szResult); nick = strval(szResult);
	cache_get_field_content(0, "IDJOC", szResult); idjoc = strval(szResult);
	cache_delete(result);
	new string[128];
	format(string, sizeof(string), "%d -> %s -> %s \n.",id, nick, idjoc);
	SCM(playerid, -1, string);
	return 1;
}

Doar ca nu-mi da nimic... iar in tabel am 5 linii puse asa de test

Link to comment
Share on other sites

Ai uitat sa pui un for care trece prin toate randurile.

for(new i, j = cache_get_row_count(); i != j; i++)
{
 cache_get_field_content_int(i, ....);
}
Edited by iMatt

Respecta si vei fi respectat.

 

BigInt Pawn:

Pacman C++: 

Snake C++:

Minesweeper C++:

 

mattbb.cash

leaks.ro

Link to comment
Share on other sites

  • Administrator

Cand vad "Cache:" -ul ala ma iau durerile de cap...

CMD:uratii(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] <= 4) return 1;

	new gQuery[0] = (EOS);
	mysql_format(SQL, gQuery, sizeof gQuery, "SELECT * FROM `urati` ORDER BY `id` DESC");
	mysql_tquery(SQL, gQuery, "arataUratii", "d", "playerid");

	return 1;
}

function arataUratii(playerid)
{
	if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");

	new id, nick[32], idjoc, string[512];

	for(new i = 0; i < cache_num_rows(); i++) 
	{
		id = cache_get_field_content_int(i, "id");
		getString(i, "NUME", nick, SQL, 128);
		idjoc = cache_get_field_content_int(i, "IDJOC");	

		format(string, sizeof string, "%d -> %s -> %d\n", id, nick, idjoc);
	}

	ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Lista cu urati", string, "Ok", "");

	return 1;
}
Link to comment
Share on other sites

Am incercat cu for..

Eu am in acel tabel 7 randuri inserate https://imgur.com/a/AIDSKTj

coloana id are INT(2) si e pe AUTO_INCREMENT
restul coloanelor (NUME, IDJOC) sunt cu TEXT

 Aici am comanda cu for dar nu imi da nimic, imi da pur si simplu o singura linie cu 0 cand o testez

CMD:showuratii(playerid, params[]) {
	if(PlayerInfo[playerid][pAdmin] <= 4) return SCM(playerid, -1, "");
	new query[128];
	format(query, sizeof(query), "SELECT * FROM `urati`");
	new Cache: result, id, nick, idjoc, szResult[256];
	result = mysql_query(SQL, query);
	for(new i, j = cache_get_row_count (); i < j; i++) {
		cache_get_field_content(0, "id", szResult); id = strval(szResult);
		cache_get_field_content(0, "NUME", szResult); nick = strval(szResult);
		cache_get_field_content(0, "IDJOC", szResult); idjoc = strval(szResult);
	}
	cache_delete(result);
	new string[128];
	format(string, sizeof(string), "%d -> %s -> %s \n.",id, nick, idjoc);
	SCM(playerid, -1, string);
	return 1;
}
Link to comment
Share on other sites

 

Cand vad "Cache:" -ul ala ma iau durerile de cap...

CMD:uratii(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] <= 4) return 1;

	new gQuery[0] = (EOS);
	mysql_format(SQL, gQuery, sizeof gQuery, "SELECT * FROM `urati` ORDER BY `id` DESC");
	mysql_tquery(SQL, gQuery, "arataUratii", "d", "playerid");

	return 1;
}

function arataUratii(playerid)
{
	if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");

	new id, nick[32], idjoc, string[512];

	for(new i = 0; i < cache_num_rows(); i++) 
	{
		id = cache_get_field_content_int(i, "id");
		getString(i, "NUME", nick, SQL, 128);
		idjoc = cache_get_field_content_int(i, "IDJOC");	

		format(string, sizeof string, "%d -> %s -> %d\n", id, nick, idjoc);
	}

	ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Lista cu urati", string, "Ok", "");

	return 1;
}

imi da o eroare cu getstring nedefinit

Link to comment
Share on other sites

Tot nu merge, se opreste la if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");

CMD:showuratii(playerid, params[]) {
	if(PlayerInfo[playerid][pAdmin] <= 4) return 1;
	new query[256];
	mysql_format(SQL, query, sizeof(query), "SELECT * FROM `urati` ORDER BY `id` DESC");
	mysql_tquery(SQL, query, "", "");
	if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");
	new id, NUME[32], IDJOC, string[512];
	for(new i = 0; i < cache_num_rows(); i++) {
		id = cache_get_field_content_int(i, "id");
		cache_get_field_content(i, "NUME", NUME, SQL, 128);
		IDJOC = cache_get_field_content_int(i, "IDJOC");
		format(string, sizeof(string), "%d -> %s -> %s\n", id, NUME, IDJOC);
		printf("%d -> %s -> %s\n", id, NUME, IDJOC);
	}
	ShowPlayerDialog(playerid, DIALOG_URATI, DIALOG_STYLE_MSGBOX, "Lista cu urati", string, "Ok", "");
	SCM(playerid, -1, string);
	return 1;
}
Link to comment
Share on other sites

 

Tot nu merge, se opreste la if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");

CMD:showuratii(playerid, params[]) {
	if(PlayerInfo[playerid][pAdmin] <= 4) return 1;
	new query[256];
	mysql_format(SQL, query, sizeof(query), "SELECT * FROM `urati` ORDER BY `id` DESC");
	mysql_tquery(SQL, query, "", "");
	if(cache_get_row_count() == 0) return SCM(playerid, -1, "Nu am gasit nici un urat in baza de date.");
	new id, NUME[32], IDJOC, string[512];
	for(new i = 0; i < cache_num_rows(); i++) {
		id = cache_get_field_content_int(i, "id");
		cache_get_field_content(i, "NUME", NUME, SQL, 128);
		IDJOC = cache_get_field_content_int(i, "IDJOC");
		format(string, sizeof(string), "%d -> %s -> %s\n", id, NUME, IDJOC);
		printf("%d -> %s -> %s\n", id, NUME, IDJOC);
	}
	ShowPlayerDialog(playerid, DIALOG_URATI, DIALOG_STYLE_MSGBOX, "Lista cu urati", string, "Ok", "");
	SCM(playerid, -1, string);
	return 1;
}

Verifica numele tabelei sa corespunda cu cel din query-ul trimis, problema este la query deoarece nu gaseste niciun rand din el.

Respecta si vei fi respectat.

 

BigInt Pawn:

Pacman C++: 

Snake C++:

Minesweeper C++:

 

mattbb.cash

leaks.ro

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...