Problem selecting from DB
#1

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");
}
Reply
#2

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);
Reply
#3

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

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

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?
Reply
#6

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

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

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!
Reply
#9

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"));
}
Reply
#10

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


Forum Jump:


Users browsing this thread: 2 Guest(s)