Not displaying correct data
#1

Hey there.
This code is really pissing me off, and I keep getting wrong result no matter what I do.
I'm trying to load data from the database and everything loads fine, my MySQL logs says it's loaded. But when I try to display the data in-game, through strings, some of the information is incorrect.

How it looks in-game:


This is what it's supposed to display:


And this is the database structure:


Here's my code:
Код:
// Enums
enum PlayerData
{
	pID,
	pName[512],
	pPassword[512],
	pAdminLevel,
	pMoney,
	pSkin,
	Float:pHealth,
	Float:pArmour
};
new Player[MAX_PLAYERS][PlayerData];

// Loading from database
stock LoadDatabase(playerid)
{	
    new query[512], health[64], armour[64];
    format(query, sizeof(query), "SELECT * FROM `samp_users` WHERE `pName` = '%s' LIMIT 1", GetName(playerid));
    mysql_query(query);
    mysql_store_result();
	
    if(mysql_fetch_row(query))
    {
                mysql_fetch_field("pID", Player[playerid][pID]);
		
		mysql_fetch_field("pName", Player[playerid][pName]);
		
		mysql_fetch_field("pPassword", Player[playerid][pPassword]);
		
		mysql_fetch_field("pAdminLevel", Player[playerid][pAdminLevel]);
		
                mysql_fetch_field("pMoney", Player[playerid][pMoney]);
		
		mysql_fetch_field("pSkin", Player[playerid][pSkin]);
		
		mysql_fetch_field("pHealth", health); Player[playerid][pHealth] = floatstr(health);
		
		mysql_fetch_field("pArmour", armour); Player[playerid][pArmour] = floatstr(armour);
    }
    mysql_free_result();
	return 1;
}

// Displaying the data
stock DebugSQL(playerid)
{	
	new string[512];
	format(string, sizeof(string), "[DEBUG] ID: %i, Name: %s, Admin: %s, Money: %s, Skin: %s, Health: %f, Armour: %f", 
	Player[playerid][pID], 
	Player[playerid][pName], 
	Player[playerid][pAdminLevel], 
	Player[playerid][pMoney], 
	Player[playerid][pSkin], 
	Player[playerid][pHealth], 
	Player[playerid][pArmour]);
	SendClientMessage(playerid, COLOR_WHITE, string);
	return 1;
}
And here is my MySQL log:
Код:
[Mon Jun 01 10:46:10 2015] -------------------------
[Mon Jun 01 10:46:10 2015]      Logging Started
[Mon Jun 01 10:46:10 2015] -------------------------
[Mon Jun 01 10:46:10 2015] Function: mysql_init executed with result: "0".
[Mon Jun 01 10:46:11 2015] Connected (0) to root @ 127.0.0.1 via TCP/IP.
[Mon Jun 01 10:46:11 2015] MySQL Server Version 5.6.24.
[Mon Jun 01 10:46:37 2015] Function: mysql_query executed: "SELECT * FROM `samp_users` WHERE `pName` = 'Michael_Puglisi' LIMIT 1" with result: "0".
[Mon Jun 01 10:46:37 2015] Function: mysql_store_result executed with result: "1"
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_row executed with result: "12|Michael_Puglisi|344907E89B981CAF221D05F597EB57A6AF408F15F4DD7895BBD1B96A2938EC24A7DCF23ACB94ECE0B6D7B0640358BC56BDB448194B9305311AFF038A834A079F|0|50056|29|3332.153564 -481.794494 3332.153564|99|10|".
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_fetch_field executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_free_result executed.
[Mon Jun 01 10:46:37 2015] Function: mysql_free_result executed.
What am I doing wrong? I'm using StrickenKid's plugin.
Please help me out here, I'll do anything in return.
Thanks a lot in advance.
Reply
#2

if you are using BlueG's mysql system then try this one to load datas from mysql
Код:
Player[playerid][pID] = cache_get_field_content_int(0, "id"); 
cache_get_field_content(0, "password", Player[playerid][pPassword], g_SQL, 129);
//=============================
//for integer and float
new var = cache_get_field_content_int(rowindex, "fieldname");
new Float;var = cache_get_field_content_float(rowindex, "fieldname");  
//for strings
cache_get_field_content(rowindex, fieldname, variable,sqlhande,lenght);
Reply
#3

What MySQL plugin are you using?
Reply
#4

Quote:
Originally Posted by Psykotikum
Посмотреть сообщение
What MySQL plugin are you using?
Oh sorry, I forgot to mention. I'm using StrickenKid's plugin.
Reply
#5

I didn't look at the whole screenshot you provided, but from what I see at the pPlayerPos part you save the float as a string am I right? how are you supposed to load it?
Save each coordinate alone! and get them separately. (Use floatstr when loading to save in variables)

I hope I helped any feedback is appreciated!
Reply
#6

Quote:
Originally Posted by Stanford
Посмотреть сообщение
I didn't look at the whole screenshot you provided, but from what I see at the pPlayerPos part you save the float as a string am I right? how are you supposed to load it?
Save each coordinate alone! and get them separately. (Use floatstr when loading to save in variables)

I hope I helped any feedback is appreciated!
I haven't used pPlayerPos in-game at all. It's just a column in my database, I haven't implemented it yet. So that is not the problem.
Reply
#7

pawn Код:
format(string, sizeof(string), "[DEBUG] ID: %i, Name: %s, Admin: %s, Money: %s, Skin: %s, Health: %f, Armour: %f",
%i or %d = integer
%s = string
%f = float

ID: %i (ID is an integer, this is correct)
Name: %s (Name is a string, this is correct)
Admin: %s (Admin is an integer, this is incorrect...)
Money: %s (Money is an integer, this is incorrect...)
Skin: %s (Skin is an integer, this is incorrect...)
Health: %f (Health is a float, this is correct)
Armour: %f (Armour is a float, this is correct)
Reply
#8

Quote:
Originally Posted by Threshold
Посмотреть сообщение
-snip-
I already tried that. Here's what it displays when I correct the strings:


Here's the code:
Код:
	new string[512];
	format(string, sizeof(string), "[DEBUG] ID: %i, Name: %s, Admin: %i, Money: %i, Skin: %i, Health: %f, Armour: %f", 
	Player[playerid][pID], 
	Player[playerid][pName], 
	Player[playerid][pAdminLevel], 
	Player[playerid][pMoney], 
	Player[playerid][pSkin], 
	Player[playerid][pHealth], 
	Player[playerid][pArmour]);
	SendClientMessage(playerid, COLOR_WHITE, string);
So I believe the strings are fine. What else could it be?
Reply
#9

new string[512] - why is this 512 I'm postive the maximum number of characters you can have in anyone string that can be displayed is 128
Reply
#10

Quote:
Originally Posted by Bennyy
Посмотреть сообщение
new string[512] - why is this 512 I'm postive the maximum number of characters you can have in anyone string that can be displayed is 128
Changed back to 128.
But that doesn't however change or fix the "bug". It's still the same. Any ideas?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)