Mysql loading tables
#1

This ties in with the last thread I made (https://sampforum.blast.hk/showthread.php?tid=526506)

I can't seem to figure this out, though i'm sure it's simple..

The objects are only loading into the server from the last project created. (the highest id) I'm assuming it has something to do with my use of a loop inside of a loop, but I don't really know another way to do this, i've never attempted anything of this sort before. Anyhow, this is my loading function.

pawn Код:
stock LoadObjects()
{
    for(new project; project<GetCreatedProjects()+1; project++)
    {
        for(new i; i<GetCreatedObjects(project)+1; i++)
        {
            LoadObject(project, i);
        }
    }
}

stock LoadObject(project, id)
{
    new Query[800], string[50];
    format(Query, sizeof(Query), "SELECT * FROM `Project_%d` WHERE `ID` = %d", project, id);
    mysql_query(Query);
    mysql_store_result();
    while(mysql_fetch_row_format(Query,"|"))
    {
        mysql_fetch_field_row(string, "ID");
        ObjectInfo[id][oID] = strval(string);
        mysql_fetch_field_row(string, "MODEL");
        ObjectInfo[id][oModel] = strval(string);
        mysql_fetch_field_row(string, "X");
        ObjectInfo[id][oX] = floatstr(string);
        mysql_fetch_field_row(string, "Y");
        ObjectInfo[id][oY] = floatstr(string);
        mysql_fetch_field_row(string, "Z");
        ObjectInfo[id][oZ] = floatstr(string);
        mysql_fetch_field_row(string, "RX");
        ObjectInfo[id][orX] = floatstr(string);
        mysql_fetch_field_row(string, "RY");
        ObjectInfo[id][orY] = floatstr(string);
        mysql_fetch_field_row(string, "RZ");
        ObjectInfo[id][orZ] = floatstr(string);
    }

    mysql_free_result();
   
    ObjectInfo[id][oProject] = project;
   
    return 1;
}
Reply
#2

Okay, I just realized the issue, i'm not 100% sure how to fix it, but what's happening is everytime it loads a project, it's writing it to a new 'id' in ObjectInfo

EDIT: I have no clue how to fix this without eliminating the array alltogether and directly pull all the info from the database directly.
Reply
#3

try to start it out from 0, just to be sure.

Код:
for(new project=0; project<GetCreatedProjects()+1; project++)
    {
        for(new i=0; i<GetCreatedObjects(project)+1; i++)
        {
edit:
your problem also might be the unique and auto-increment inside the mysql itself.
Reply
#4

Quote:
Originally Posted by Hanger
Посмотреть сообщение
try to start it out from 0, just to be sure.

Код:
for(new project=0; project<GetCreatedProjects()+1; project++)
    {
        for(new i=0; i<GetCreatedObjects(project)+1; i++)
        {
edit:
your problem also might be the unique and auto-increment inside the mysql itself.
I've sorted through all of that, I know for sure that in the array

ObjectInfo[ID][oInfo]; the ID is being written over.
Reply
#5

Used a 3D variable for the enum on the objects, works now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)