Problem with my house system.
#1

I have made a house system but its not saving or loading anything.

Code:
stock CreateHouse(cijena, Float:X, Float:Y, Float:Z, Float:kIntX, Float:kIntY, Float:kIntZ, adresa[], intid)
{
    new Field[16], DBResult:Result;
 	
 	new Query[128], i, string[64];
    new DBResult:qresult;
    qresult = db_query(Database,"SELECT * FROM `HOUSES`");
    format(Query,sizeof(Query),"%d", db_num_rows(qresult));
    format(string, sizeof string, "%d", i);
 	print(string);

 	HouseInfo[i][ID] = i+1;
	HouseInfo[i][Cijena] = cijena;
	HouseInfo[i][kX] = X;
	HouseInfo[i][kY] = Y;
	HouseInfo[i][kZ] = Z;
	HouseInfo[i][IntX] = kIntX;
	HouseInfo[i][IntY] = kIntY;
	HouseInfo[i][IntZ] = kIntZ;
	HouseInfo[i][Interior] = intid;
 	db_free_result(qresult);

	format(Query, sizeof(Query), "INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA', 'NOVAC', 'BRAVA', 'INT', 'RENTABIL', 'RENT', 'ALARM') VALUES('%s','%s')", DB_Escape(HouseInfo[i][ID]), 0);
 	db_query(Database, Query);

	format(Query, sizeof(Query), "UPDATE `HOUSES` SET VLASNIK = '0', CIJENA = '%d', ADRESA = '%s', X = '%f', Y = '%f', Z = '%f' WHERE `ID` = '%d' ", HouseInfo[i][Cijena], adresa, HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ], HouseInfo[i][ID]);
 	db_query(Database, Query);

 	format(Query, sizeof(Query), "UPDATE `HOUSES` SET INTX = '%f', INTY = '%f', INTZ = '%f', MATS = '%d', DROGA = '%d', NOVAC = '%d', BRAVA = '%d', NAPRODAJU = '1' WHERE `ID` = '%d' ", HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ], HouseInfo[i][kMats], HouseInfo[i][kDroga], HouseInfo[i][kNovac], HouseInfo[i][Brava], HouseInfo[i][ID]);
 	db_query(Database, Query);
 	
 	format(Query, sizeof(Query), "UPDATE `HOUSES` SET INT = '%d', RENTABIL = '%d', RENT = '%d', ALARM = '%d' WHERE `ID` = '%d' ", HouseInfo[i][Interior], HouseInfo[i][Rentabil], HouseInfo[i][Rent], HouseInfo[i][Alarm], HouseInfo[i][ID]);
 	db_query(Database, Query);

    db_get_field_assoc(Result, "ADRESA", Field, 30);
	HouseInfo[i][Adresa] = strval(Field);
	LoadHouse(HouseInfo[i][ID]);
	format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]);
	HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,LIGHTBLUE,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.1,15.0,0,1);
	return 1;
}


Code:
stock LoadHouse(i)
{
	new Query[150], Field[16], DBResult:Result, string[64];
    format(Query, sizeof(Query), "SELECT * FROM `HOUSES` WHERE `ID` = '%d'", i);
	Result = db_query(Database, Query);
 	format(string, sizeof string, "%s", i);
 	print(string);
 	if(db_num_rows(Result))
  	{
		HouseInfo[i][ID] = i;
		db_get_field_assoc(Result, "NAPRODAJU", Field, 30);
		HouseInfo[i][KucaNaProdaju] = strval(Field);
		db_get_field_assoc(Result, "VLASNIK", Field, 30);
		HouseInfo[i][Vlasnik] = strval(Field);
		db_get_field_assoc(Result, "CIJENA", Field, 30);
		HouseInfo[i][Cijena] = strval(Field);
		db_get_field_assoc(Result, "VRSTAKUCE", Field, 30);
		HouseInfo[i][VrstaKuce] = strval(Field);
		db_get_field_assoc(Result, "ADRESA", Field, 30);
		HouseInfo[i][Adresa] = strval(Field);
		db_get_field_assoc(Result, "X", Field, 30);
		HouseInfo[i][kX] = strval(Field);
		db_get_field_assoc(Result, "Y", Field, 30);
		HouseInfo[i][kY] = strval(Field);
		db_get_field_assoc(Result, "Z", Field, 30);
		HouseInfo[i][kZ] = strval(Field);
		db_get_field_assoc(Result, "INTX", Field, 30);
		HouseInfo[i][IntX] = strval(Field);
		db_get_field_assoc(Result, "INTY", Field, 30);
		HouseInfo[i][IntY] = strval(Field);
		db_get_field_assoc(Result, "INTZ", Field, 30);
		HouseInfo[i][IntZ] = strval(Field);
		db_get_field_assoc(Result, "MATS", Field, 30);
		HouseInfo[i][kMats] = strval(Field);
		db_get_field_assoc(Result, "DROGA", Field, 30);
		HouseInfo[i][kDroga] = strval(Field);
		db_get_field_assoc(Result, "NOVAC", Field, 30);
		HouseInfo[i][kNovac] = strval(Field);
		db_get_field_assoc(Result, "BRAVA", Field, 30);
		HouseInfo[i][Brava] = strval(Field);
		db_get_field_assoc(Result, "INT", Field, 30);
		HouseInfo[i][Interior] = strval(Field);
		db_get_field_assoc(Result, "RENTABIL", Field, 30);
		HouseInfo[i][Rentabil] = strval(Field);
		db_get_field_assoc(Result, "RENT", Field, 30);
		HouseInfo[i][Rent] = strval(Field);
		db_get_field_assoc(Result, "ALARM", Field, 30);
		HouseInfo[i][Alarm] = strval(Field);
		if(HouseInfo[i][KucaNaProdaju] == 1)
  		{
			format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\nOpis:"BIJELA" %s\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]);
   			HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1);
      	}
      	if(HouseInfo[i][KucaNaProdaju] == 0 && HouseInfo[i][Rentabil] == 1)
		{
			format(KucniLabel,sizeof(KucniLabel),""ZELENA"Vlasnik: {FFFFFF}%s\n"ZELENA"Rent: {FFFFFF}%d$\n"ZELENA"Adresa: "BIJELA"%s", HouseInfo[i][Vlasnik],HouseInfo[i][Rent],HouseInfo[i][Adresa]);
			HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel ,0x00FFFFAA,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.5,15.0, 0, 1);
		}
       	else
        {
        	format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Vlasnik: "BIJELA"%s\n"ZELENA"Opis: "BIJELA"%s\n"ZELENA"Adresa: "BIJELA"%s",HouseInfo[i][Vlasnik],HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa]);
         	HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1);
        }
	}
	return 1;
}
Reply
#2

print the queries, and post what they output.

also, why are you trying to escape an integer (I assume)?
pawn Code:
DB_Escape(HouseInfo[i][ID])
Reply
#3

[07:08:33] 0
[07:08:33] ђ0 but there is a wierd sign in front

Yes u assumed right.
Reply
#4

Print the queries as in below every
pawn Code:
format(Query, // etc...
add
pawn Code:
print(Query);
Reply
#5

Code:
0
[07:17:07] INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA',
[07:17:07] UPDATE `HOUSES` SET VLASNIK = '0', CIJENA = '10000', ADRESA = 'Spawn', X = '1366.969726', Y = '-1383.997680', Z = '13.678855' W
[07:17:07] UPDATE `HOUSES` SET INTX = '2324.419921', INTY = '-1145.568359', INTZ = '1050.710083', MATS = '0', DROGA = '0', NOVAC = '0', BR
[07:17:07] UPDATE `HOUSES` SET INT = '12', RENTABIL = '0', RENT = '0', ALARM = '0' WHERE `ID` = '1' 
[07:17:07] 00
[07:17:07] SELECT * FROM `HOUSES` WHERE `ID` = '1'
Code:
stock LoadHouse(i)
{
	new Query[150], Field[16], DBResult:Result, string[64];
    format(Query, sizeof(Query), "SELECT * FROM `HOUSES` WHERE `ID` = '%d'", i);
	Result = db_query(Database, Query);
 	format(string, sizeof string, "%s", i);
 	print(string);
 	print(Query);
 	if(db_num_rows(Result))
  	{
		HouseInfo[i][ID] = i;
		db_get_field_assoc(Result, "NAPRODAJU", Field, 30);
		HouseInfo[i][KucaNaProdaju] = strval(Field);
		db_get_field_assoc(Result, "VLASNIK", Field, 30);
		HouseInfo[i][Vlasnik] = strval(Field);
		db_get_field_assoc(Result, "CIJENA", Field, 30);
		HouseInfo[i][Cijena] = strval(Field);
		db_get_field_assoc(Result, "VRSTAKUCE", Field, 30);
		HouseInfo[i][VrstaKuce] = strval(Field);
		db_get_field_assoc(Result, "ADRESA", Field, 30);
		HouseInfo[i][Adresa] = strval(Field);
		db_get_field_assoc(Result, "X", Field, 30);
		HouseInfo[i][kX] = strval(Field);
		db_get_field_assoc(Result, "Y", Field, 30);
		HouseInfo[i][kY] = strval(Field);
		db_get_field_assoc(Result, "Z", Field, 30);
		HouseInfo[i][kZ] = strval(Field);
		db_get_field_assoc(Result, "INTX", Field, 30);
		HouseInfo[i][IntX] = strval(Field);
		db_get_field_assoc(Result, "INTY", Field, 30);
		HouseInfo[i][IntY] = strval(Field);
		db_get_field_assoc(Result, "INTZ", Field, 30);
		HouseInfo[i][IntZ] = strval(Field);
		db_get_field_assoc(Result, "MATS", Field, 30);
		HouseInfo[i][kMats] = strval(Field);
		db_get_field_assoc(Result, "DROGA", Field, 30);
		HouseInfo[i][kDroga] = strval(Field);
		db_get_field_assoc(Result, "NOVAC", Field, 30);
		HouseInfo[i][kNovac] = strval(Field);
		db_get_field_assoc(Result, "BRAVA", Field, 30);
		HouseInfo[i][Brava] = strval(Field);
		db_get_field_assoc(Result, "INT", Field, 30);
		HouseInfo[i][Interior] = strval(Field);
		db_get_field_assoc(Result, "RENTABIL", Field, 30);
		HouseInfo[i][Rentabil] = strval(Field);
		db_get_field_assoc(Result, "RENT", Field, 30);
		HouseInfo[i][Rent] = strval(Field);
		db_get_field_assoc(Result, "ALARM", Field, 30);
		HouseInfo[i][Alarm] = strval(Field);
		if(HouseInfo[i][KucaNaProdaju] == 1)
  		{
			format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\nOpis:"BIJELA" %s\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]);
   			HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1);
      	}
      	if(HouseInfo[i][KucaNaProdaju] == 0 && HouseInfo[i][Rentabil] == 1)
		{
			format(KucniLabel,sizeof(KucniLabel),""ZELENA"Vlasnik: {FFFFFF}%s\n"ZELENA"Rent: {FFFFFF}%d$\n"ZELENA"Adresa: "BIJELA"%s", HouseInfo[i][Vlasnik],HouseInfo[i][Rent],HouseInfo[i][Adresa]);
			HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel ,0x00FFFFAA,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.5,15.0, 0, 1);
		}
       	else
        {
        	format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Vlasnik: "BIJELA"%s\n"ZELENA"Opis: "BIJELA"%s\n"ZELENA"Adresa: "BIJELA"%s",HouseInfo[i][Vlasnik],HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa]);
         	HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1);
        }
	}
	return 1;
}

stock CreateHouse(cijena, Float:X, Float:Y, Float:Z, Float:kIntX, Float:kIntY, Float:kIntZ, adresa[], intid)
{
    new Field[16], DBResult:Result;
 	
 	new Query[128], i, string[64];
    new DBResult:qresult;
    qresult = db_query(Database,"SELECT * FROM `HOUSES`");
    format(Query,sizeof(Query),"%d", db_num_rows(qresult));
    format(string, sizeof string, "%d", i);
 	print(string);

 	HouseInfo[i][ID] = i+1;
	HouseInfo[i][Cijena] = cijena;
	HouseInfo[i][kX] = X;
	HouseInfo[i][kY] = Y;
	HouseInfo[i][kZ] = Z;
	HouseInfo[i][IntX] = kIntX;
	HouseInfo[i][IntY] = kIntY;
	HouseInfo[i][IntZ] = kIntZ;
	HouseInfo[i][Interior] = intid;
 	db_free_result(qresult);

	format(Query, sizeof(Query), "INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA', 'NOVAC', 'BRAVA', 'INT', 'RENTABIL', 'RENT', 'ALARM') VALUES('%s','%s')", HouseInfo[i][ID], 0);
 	db_query(Database, Query);
 	print(Query);

	format(Query, sizeof(Query), "UPDATE `HOUSES` SET VLASNIK = '0', CIJENA = '%d', ADRESA = '%s', X = '%f', Y = '%f', Z = '%f' WHERE `ID` = '%d' ", HouseInfo[i][Cijena], adresa, HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ], HouseInfo[i][ID]);
 	db_query(Database, Query);
 	print(Query);

 	format(Query, sizeof(Query), "UPDATE `HOUSES` SET INTX = '%f', INTY = '%f', INTZ = '%f', MATS = '%d', DROGA = '%d', NOVAC = '%d', BRAVA = '%d', NAPRODAJU = '1' WHERE `ID` = '%d' ", HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ], HouseInfo[i][kMats], HouseInfo[i][kDroga], HouseInfo[i][kNovac], HouseInfo[i][Brava], HouseInfo[i][ID]);
 	db_query(Database, Query);
 	print(Query);
 	
 	format(Query, sizeof(Query), "UPDATE `HOUSES` SET INT = '%d', RENTABIL = '%d', RENT = '%d', ALARM = '%d' WHERE `ID` = '%d' ", HouseInfo[i][Interior], HouseInfo[i][Rentabil], HouseInfo[i][Rent], HouseInfo[i][Alarm], HouseInfo[i][ID]);
 	db_query(Database, Query);
 	print(Query);

    db_get_field_assoc(Result, "ADRESA", Field, 30);
	HouseInfo[i][Adresa] = strval(Field);
	LoadHouse(HouseInfo[i][ID]);
	format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]);
	HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,LIGHTBLUE,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.1,15.0,0,1);
	return 1;
}
and how i did it.
Reply
#6

I have fixed the db_num_rows part but it still does not write in database.
Reply
#7

bump
Reply
#8

try to increase this

pawn Code:
new Query[150]

//too something bigger like
new Query[300]

your querys where being cut off at the end.
so if the above still dont work you may have to go bigger,

I have one global var strQuery[1024]
that i use across my mode but in a functions like yours
a local should be close to the size of the data
Reply
#9

I did it,i have 5 tables that i made and when i create house it dont saves again,i set the field to a 512

Here is the server.log

Code:
[15:22:03] INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA', 'NOVAC', 'BRAVA', 'INT', 'RENTABIL', 'RENT', 'ALARM') VALUES('','')
[15:22:03] UPDATE `HOUSES` SET VLASNIK = '0', CIJENA = '10005', ADRESA = 'spawn', X = '1367.134399', Y = '-1384.125488', Z = '13.679667' WHERE `ID` = '6' 
[15:22:03] UPDATE `HOUSES` SET INTX = '2324.419921', INTY = '-1145.568359', INTZ = '1050.710083', MATS = '0', DROGA = '0', NOVAC = '0', BRAVA = '0', NAPRODAJU = '1' WHERE `ID` = '6' 
[15:22:03] UPDATE `HOUSES` SET INT = '12', RENTABIL = '0', RENT = '0', ALARM = '0' WHERE `ID` = '6' 
[15:22:03] 
[15:22:03] SELECT * FROM `HOUSES` WHERE `ID` = '6'
Reply
#10

pawn Code:
INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA', 'NOVAC', 'BRAVA', 'INT', 'RENTABIL', 'RENT', 'ALARM') VALUES('','')
look at VALUES

for one it had nothing in it and 2 it does not match the fields.

also the fields should not be wrapped in 'field' quotes
try using `field`

im off to work

goodluck
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)