SA-MP Forums Archive
Problem selecting from DB - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem selecting from DB (/showthread.php?tid=253789)



Problem selecting from DB - Narxon - 08.05.2011

First I wanted to apologize for my bad English.
My problem is this, I have this code to select three values ​​of the database and display it in a menu but do not display any values, the fields are spelled correctly and compiling not throw any error or warning. Thanks for your time and hope you can help me.

Код:
forward GetCuData(playerid, campo[]);
public GetCuData(playerid, campo[])
{
	new tmp[128];
	new row[60];
	format(tmp, 128, "SELECT %s FROM cucus WHERE ID= %d LIMIT 1", campo, cuInfo[playerid][cuSQLID]);
	mysql_query(tmp);
	mysql_store_result();
	mysql_fetch_row(row);
	new id;
	id = strval(row);
	mysql_free_result();
	return id;
}

forward AsignCuInfo(playerid);
public AsignCuInfo(playerid)
{
 	CuInfo[playerid][Sabor1]=GetCuData(playerid,"Sabor1");
	CuInfo[playerid][Sabor2]=GetCuData(playerid,"Sabor2");
	CuInfo[playerid][Sabor3]=GetCuData(playerid,"Sabor3");
}

forward OnCuCrear(playerid);
public OnCuCrear(playerid)
{
	AsignCuInfo(playerid);
    new stringmenu[128];
	format(stringmenu, sizeof(stringmenu), "%s \n %s \n %s",CuInfo[playerid][Sabor1],CuentaInfo[playerid][Sabor2],CuentaInfo[playerid][Sabor3]);
   	ShowPlayerDialog(playerid, CU_MENU,DIALOG_STYLE_LIST, "Elige el cucurucho que quieres comer",stringmenu, "Seleccionar", "Salir");
}



Re: Problem selecting from DB - Georgelopez1 - 08.05.2011

Take the string out from in between the SELECT FROM

Try replacing your format with this:
pawn Код:
format(tmp, 128, "SELECT FROM `cucus` WHERE ID = %d ", cuInfo[playerid][cuSQLID]);
mysql_query(tmp);



Re: Problem selecting from DB - MadeMan - 08.05.2011

I think you want to return a string

pawn Код:
forward GetCuData(playerid, campo[]);
public GetCuData(playerid, campo[])
{
    new tmp[128];
    new row[60];
    format(tmp, 128, "SELECT %s FROM cucus WHERE ID= %d LIMIT 1", campo, cuInfo[playerid][cuSQLID]);
    mysql_query(tmp);
    mysql_store_result();
    mysql_fetch_row(row);
    mysql_free_result();
    return row;
}



Respuesta: Problem selecting from DB - Narxon - 08.05.2011

I want to return is only a taste, just one word, not a string
if i use return row pawno returns that error on compiling: public functions may not return arrays (symbol "GetCuentaData")
T_T


Re: Respuesta: Problem selecting from DB - MadeMan - 08.05.2011

Quote:
Originally Posted by Narxon
Посмотреть сообщение
I want to return is only a taste, just one word, not a string
if i use return row pawno returns that error on compiling: public functions may not return arrays (symbol "GetCuentaData")
T_T
A word is a string too btw

Does it have to be a public function?


Respuesta: Problem selecting from DB - Narxon - 08.05.2011

No, does not need a public function ... but is the only way I know to do, I'm beginner in pawn


Re: Problem selecting from DB - MadeMan - 08.05.2011

Quote:
Originally Posted by Narxon
Посмотреть сообщение
No, does not need a public function ... but is the only way I know to do, I'm beginner in pawn
Then this should do

pawn Код:
GetCuData(playerid, campo[])
{
    new tmp[128];
    new row[60];
    format(tmp, 128, "SELECT %s FROM cucus WHERE ID= %d LIMIT 1", campo, cuInfo[playerid][cuSQLID]);
    mysql_query(tmp);
    mysql_store_result();
    mysql_fetch_row(row);
    mysql_free_result();
    return row;
}



Respuesta: Problem selecting from DB - Narxon - 08.05.2011

Well, now I get this error ...
array sizes do not match, or destination array is too small
and in these line I have:
CuInfo [playerid] [Sabor1] = GetCuData (playerid, "Sabor1");
CuInfo [playerid] [Sabor2] = GetCuData (playerid, "Sabor2");
CuInfo [playerid] [Sabor3] = GetCuData (playerid, "Sabor3");
But at least it does not fail for be public function!


Re: Problem selecting from DB - MadeMan - 08.05.2011

Put this to your script

pawn Код:
#define strcpy(%0,%1,%2) %0[0]=0;strcat(%0,%2,%1)
Then

pawn Код:
AsignCuInfo(playerid)
{
    strcpy(CuInfo[playerid][Sabor1], 64, GetCuData(playerid, "Sabor1"));
    strcpy(CuInfo[playerid][Sabor2], 64, GetCuData(playerid, "Sabor2"));
    strcpy(CuInfo[playerid][Sabor3], 64, GetCuData(playerid, "Sabor3"));
}



Respuesta: Problem selecting from DB - Narxon - 08.05.2011

OH MY GOD I LOVE YOU!! not literally of course XD It works! thank you!