SA-MP Forums Archive
help with mysql. - 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)
+--- Thread: help with mysql. (/showthread.php?tid=522478)



help with mysql. - Equality - 27.06.2014

hello. how can i retive data in mysql from column without callback?
thanks


Re: help with mysql. - Faisal_khan - 27.06.2014

What do you exactly mean?


Re: help with mysql. - Equality - 27.06.2014

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
What do you exactly mean?
i mean, if i'll try to get money from mysql
like that exmple:
format(str,sizeof(str),"SELECT * FROM accounts WHERE username='%s'",pInfo[playerid][pName]);
mysql_function_query(db,str,false,"","");
new money = cache_get_field_content_int(0,"Money",db);

it wont get the field that i want... it will return 0..
why? what im doing worng

(sorry for my bad english :X, please try to understand me)


Re: help with mysql. - Faisal_khan - 27.06.2014

You are doing it wrong. What are you fetching from here?:
pawn Код:
format(str,sizeof(str),"SELECT * FROM accounts WHERE username='%s'",pInfo[playerid][pName]);
The right way is this:
pawn Код:
new row, field, money;
cache_get_data(row, field, db);
if(rows == 1)
{
        cache_get_field_content_int(0,"Money", money, db);
}



Re: help with mysql. - Equality - 27.06.2014

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
You are doing it wrong. What are you fetching from here?:
pawn Код:
format(str,sizeof(str),"SELECT * FROM accounts WHERE username='%s'",pInfo[playerid][pName]);
The right way is this:
pawn Код:
new row, field, money;
cache_get_data(row, field, db);
if(rows == 1)
{
        cache_get_field_content_int(0,"Money", money, db);
}
but how should i fetch that? i mean... how could i get it from the username that i want?
i mean, whats the query comes before that getdata?


Re: help with mysql. - Konstantinos - 27.06.2014

Using y_inline (from YSI):
pawn Код:
native mysql_tquery_inline(connHandle, query[], callback:Callback, format[], {Float,_}:...);
An example of using y_inline can be found: https://sampforum.blast.hk/showthread.php?tid=295049
Look at the bottom of the first post.


Re: help with mysql. - Faisal_khan - 27.06.2014

Well you will have to create a callback:
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
      new row, field, money;
      cache_get_data(row, field, db);
      if(rows == 1)
      {
             cache_get_field_content_int(0,"Money", money, db);
      }
}
And your query:
pawn Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM playerdata WHERE username = '%e' LIMIT 1", pInfo[playerid][pName]);
                    mysql_tquery(mysql, query, "LoadAccount", "i", playerid);



Re: help with mysql. - Equality - 27.06.2014

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
Well you will have to create a callback:
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
      new row, field, money;
      cache_get_data(row, field, db);
      if(rows == 1)
      {
             cache_get_field_content_int(0,"Money", money, db);
      }
}
And your query:
pawn Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM playerdata WHERE username = '%e' LIMIT 1", pInfo[playerid][pName]);
                    mysql_tquery(mysql, query, "LoadAccount", "i", playerid);
thats the problem.
i want to fetch that without a callback :X.


Re: help with mysql. - Faisal_khan - 27.06.2014

Like this:
pawn Код:
mysql_query("SELECT `Money` FROM `accounts` WHERE `username` = '%s'", pInfo[playerid][pName]);//fetching the data
mysql_store_result();//storing the data
new money = mysql_fetch_int();//inserting the data in your variable
mysql_free_result();//and then removing the data which we stored earlier



Re: help with mysql. - Equality - 27.06.2014

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
Like this:
pawn Код:
mysql_query("SELECT `Money` FROM `accounts` WHERE `username` = '%s'", pInfo[playerid][pName]);//fetching the data
mysql_store_result();//storing the data
new money = mysql_fetch_int();//inserting the data in your variable
mysql_free_result();//and then removing the data which we stored earlier
is it possible with R34?