help with mysql.
#1

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

What do you exactly mean?
Reply
#3

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)
Reply
#4

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

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)