MYSQL > Quering[QUICK HELP]
#1

Hy , I am new in SAMP programing and currently working on MySQL..

I have created a MySQL query ONPLAYERCONNECT() and query is working but , I can't get data from row...

Here the Code
PHP код:
    format(Stringsizeof(String), "SELECT score FROM `p_data` WHERE username = '%s' LIMIT 1"P_Name);
    new 
query_run mysql_query(String);
     if(!
query_run) return SendClientMessage(playerid,C_WHITE,"Qeury Failed!");
    else
    
SendClientMessage(playerid,C_WHITE,"Qeury Run!");
    
mysql_store_result();
    new 
rows mysql_num_rows();
    if(!
rows)
    {
        
SendClientMessage(playerid,C_WHITE,"Your Account is Not Registered!");
    }
    else if(
rows == 1)
    {
        new 
data[10];
        
mysql_fetch_field_row(data,"score"); P_Var[playerid][p_Score] = strval(data);
        
SetPlayerScore(playerid,P_Var[playerid][p_Score]);
        
format(String,sizeof(String),"Score:%d",P_Var[playerid][p_Score]);
        
SendClientMessage(playerid,C_WHITE,String);
    } 
OUTPUT:
Код:
Query Run!
Score:0 //here am getting score zero but its 15 in database
Reply
#2

Any one know what is wrong ?
Reply
#3

Change

pawn Код:
mysql_fetch_field_row(data,"score");
to

pawn Код:
mysql_fetch_row(data);
Reply
#4

Delete that 'new query_run' thing as mysql_query doesn't return a specific value. Put mysql_debug(1) under OnGameModeInit and then paste what is in your mysql debug file (located in your server directory) here.
Reply
#5

Here's the Result

Код:
[11:29:26] >> mysql_connect( )

[11:29:26] CMySQLHandler::Connect() - Connection was successful.

[11:29:26] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[11:29:26]  

[11:29:26] ---------------------------

[11:29:26] MySQL Debugging activated (02/04/12)

[11:29:26] ---------------------------

[11:29:26]  

[11:29:26] >> mysql_query( Connection handle: 1 )

[11:29:26] CMySQLHandler::Query(SELECT score FROM `p_data` WHERE username = 'Rana' LIMIT 1) - Successfully executed.

[11:29:26] >> mysql_store_result( Connection handle: 1 )

[11:29:26] CMySQLHandler::StoreResult() - Result was stored.

[11:29:26] >> mysql_num_rows( Connection handle: 1 )

[11:29:26] CMySQLHandler::NumRows() - Returned 1 row(s)

[11:29:26] >> mysql_fetch_field_row( Connection handle: 1 )

[11:29:26] CMySQLHandler::FetchField(score) - You cannot call this function now. (Reason: Fields/Rows are empty.)
Reply
#6

Help ?
Reply
#7

are you sure its called score and not Score, scOre ScoRE or something else?
Reply
#8

Yup its score.....
Reply
#9

any one?
Reply
#10

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
Delete that 'new query_run' thing as mysql_query doesn't return a specific value. Put mysql_debug(1) under OnGameModeInit and then paste what is in your mysql debug file (located in your server directory) here.
Contrary to what the wiki might say, most functions DO indeed return a value. mysql_query is no different. It returns 1 on success and 0 on failure. I even went to test it for verification.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)