[Solved] Getting data into MySQL table easier.
#1

I've saved 591 vehicles using /save command and added them into my GM, but now i'm moving to mysql, and i need to get:

pawn Код:
m // model ID
x
y
z
a // angle
c // color 1
c2 // color 2
r // respawn delay
into a table. This table has:
Код:
ID
X
Y
Z
A
C
C
R
I made a command which had a loop and got all the 591 IDs into the table:
pawn Код:
CMD:auto(playerid, params[])
{
    #pragma unused params
   
    new
      query[50];
     
    for(new i = 0; i < 591; i ++)
    {
        format(query, sizeof(query), "INSERT INTO `vehicles` (ID) VALUE ('%d')", i);
        mysql_query(query);
    }
    return 1;
}
But i don't know how to get x y z a c c and r into the table faster (as that command). Can anyone help me?
Reply
#2

After i, add the location of those variables, since you did not include where they are from. (Ex: CarInfo enum)
pawn Код:
CMD:auto(playerid, params[])
{
    #pragma unused params
    new query[50];
    for(new i = 0; i < 591; i ++)
    {
        format(query, sizeof(query), "INSERT INTO `vehicles` (ID) VALUE (%d,%f,%f,%f,%f,%d,%d,%d)", i,);
        mysql_query(query);
    }
    return 1;
}
Reply
#3

I got it solved... i made a loop and used an array:

pawn Код:
new Float:Veh[590][4] =
{
  {x,y,z,a},
  .
  .
  .
};
pawn Код:
CMD:saveee(playerid, params[])
{
  #pragma unused params
  new
    query[];

  for(new i = 0; i < 591; i ++)
  {
    format(query, sizeof(query), "UPDATE `table` SET x='%.4f', y='%.4f', z='%.4f', a='%.4f' WHERE ID='%d'", Veh[i][0], Veh[i][1], Veh[i][2], Veh[i][3], i);
    mysql_query(query);
    printf("%d", i); // this was important
  }
  return 1;
}
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)