#1

Hey I was looking for an explanation about this
PHP код:
cache_get_value_int(0/*Why 0 here?*/"Name", var); 
Reply
#2

https://sampwiki.blast.hk/wiki/MySQL#ca...value_name_int

First row (it always starts from 0).
Reply
#3

So if I have more rows with same "Name" I have to use a for loop?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
And you need to use any loop, `for` is just one type.
Could you do a short example? I'd be grateful!
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
Код:
while (x)
{
}
That means "while x > 0" right?
Reply
#6

Thanks!!

Edit: Here is my problem:

PHP код:
stock SaveObjects(playeridid)
{
    new 
DB_Query[256];
    
mysql_format(Database2DB_Querysizeof DB_Query"SELECT * FROM `usersobjectsinfo` WHERE `USERNAME` = '%e'"P[playerid][Name]);
    
mysql_tquery(Database2DB_Query"OnPlayerSaveObjects""ii"playeridid);
    print(
"query sent. Calling OnPlayerSaveObjects");
    return 
1;
}
forward OnPlayerSaveObjects(playeridid);
public 
OnPlayerSaveObjects(playeridid){
    print(
"OnPlayerSaveObjects called");
    new 
Cacherand cache_save(), tempid0;
    
cache_set_active(rand);
    new 
DB_Query[256];
    while(
cache_num_rows())
    {
        print(
"cache num rows are != 0");
        
cache_get_value_int(0"OBJECTID"tempid0);
        
printf("id= %d tempid0= %d"idtempid0);
        
// CODE BELOW DOESN'T GET EXECUTED
    
if(id == tempid0){
        
mysql_format(Database2DB_Querysizeof DB_Query"UPDATE `usersobjectsinfo` SET `POSX`=%0.4f,`POSY`=%0.4f,`POSZ`=%0.4f,`ROTX`=%0.4f,`ROTY`=%0.4f,`ROTZ`=%0.4f,`OBJECTID`=%d WHERE `USERNAME`= '%e' LIMIT 1"
        
Obj[id][PosX], Obj[id][PosY], Obj[id][PosZ], Obj[id][RX], Obj[id][RY], Obj[id][RX], idObj[id][ObjOwner]);
        
printf("%s tempid0 = id"Obj[id][ObjOwner]);
        
mysql_tquery(Database2DB_Query);
        
cache_delete(rand);     
        return 
1;
    }
        
mysql_format(Database2DB_Querysizeof DB_Query"INSERT INTO `usersobjectsinfo` (`USERNAME`,`POSX`,`POSY`,`POSZ`,`ROTX`,`ROTY`,`ROTZ`,`OBJECTID`) VALUES ('%e','%0.3f','%0.3f','%0.3f','%0.3f','%0.3f','%0.3f','%d')"
        
P[playerid][Name],Obj[id][PosX], Obj[id][PosY], Obj[id][PosZ], Obj[id][RX], Obj[id][RY], Obj[id][RX], id);
        
printf("%s tempid0 != id"Obj[id][ObjOwner]);
        
mysql_tquery(Database2DB_Query);
        
cache_delete(rand);
        return 
1;
    }
    return print(
"Couldnt execute any object-saving queries");

Reply
#7

It does not move to next row (as in SQLite) by itself so the `while` loop would be same as `for`.
pawn Код:
new i = 0, rows = cache_num_rows();

while (i < rows)
{
    // cache functions

    i++;
}
pawn Код:
for (new i = 0, rows = cache_num_rows(); i < rows; i++)
{
    // cache functions
}
I noticed something that it is very weird. Why do you save cache, set active cache and delete cache? Threaded queries do this on their own. Remove it altogether.

About your method, an INSERT INTO .. ON DUPLICATE is better. If you can provide more details about your tables and what you are trying to do by checking if the object has been saved or not, we can fix it.
Reply
#8

Sorry for the delay, had to cook dinner

https://pastebin.com/2xJfgexv
Reply
#9

pawn Код:
#define MAX_POBJECTS 35

// When server starts
// for(new i = 0; i < MAX_POBJECTS; i++)LoadObjects(i);
 
LoadObjetcs(id){
    Obj[id][Exists] = 0;
    new DB_Query[64];
    mysql_format(Database2, DB_Query, sizeof(DB_Query), "SELECT * FROM `usersobjectsinfo`");
    mysql_tquery(Database2, DB_Query, "LoadObjectsCoordinates","i", id);
    return 1;
 
}
You execute `LoadObjects` 35 times but your query selects all the data each time. Execute 1 query and a loop to load all the objects at once.

Does it also mean that a player can only create 1 object (35 players max) or 35 objects per player?

Remove the save cache, set active cache and delete cache parts.

pawn Код:
strcat(DB_Query, "CREATE TABLE IF NOT EXISTS `usersobjectsinfo`");
        strcat(DB_Query,"(`ID` int(11) NOT NULL AUTO_INCREMENT,");
        strcat(DB_Query,"`USERNAME` varchar(24),`POSX` float(12),"); // To get track of who created that obj
        strcat(DB_Query,"`POSY` float(12),");
        strcat(DB_Query,"`POSZ` float(12),");
        strcat(DB_Query,"`ROTX` float(12),");
        strcat(DB_Query,"`ROTY` float(12),");
        strcat(DB_Query,"`ROTZ` float(12),");
        strcat(DB_Query,"`OBJECTID` mediumint(7) NOT NULL,");
        strcat(DB_Query,"PRIMARY KEY (`ID`))");
The main reason I had suggested to you to use 2 tables was to avoid storing the name of player in each row. At least, insert the registration ID instead.

What pair is unique? userid + objectid
Set those two columns as a UNIQUE KEY (yes, multi-column in 1 key). Now you do not even need the select query, nor checking if x is equal to y.

pawn Код:
INSERT INTO usersobjectsinfo (...) VALUES (...) ON DUPLICATE KEY UPDATE ...
Reply
#10

Will get into this soon! Tried to give you some reputation.. I don't get why it's not possible
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)