Array and MySQL -
KingArthur - 05.07.2009
Hello i'm now realy ...
In some of my includes i have this:
Код:
stock GetJobData(field[])
{
new tmp[MAX_QUERY];
new result[MAX_QUERY];
new array[50];
format(tmp, sizeof(tmp), "SELECT %s FROM %s", field, JOB_TABLE);
MySQL_query(tmp);
MySQL_result();
while(MySQL_fetch(result))
{
for(new i=0;i<sizeof(array);i++)
{
array[i]=result[i];
}
}
return array;
}
In my Gamemode i use this:
Код:
new array[50];
new formatstring[50];
new formatarray[50];
array = GetJobData("spawn_x");
for(new i=0; i<sizeof(array); i++)
{
format(formatstring, sizeof(formatstring), "%s", array[i]);
formatarray[i] = formatstring; // (88) : error 006: must be assigned to an array
print(formatarray[i]);
}
Error:
Quote:
(8 : error 006: must be assigned to an array
|
Can you hep me?
AND
Why is there no why to use the content of the database like in php?
Example: print(value[row1]); ?
ThX, my head is bursting equal
Re: Array and MySQL -
Nero_3D - 05.07.2009
you do
cell (formatarray[i]) = array (formatstring)
but you need to do
array = array
Re: Array and MySQL -
KingArthur - 05.07.2009
HI puh someone help me THANK YOU
Im not alone hihi.
Well can you change it please? I write now over 2-3 hours on THIS little code and everytime a other error or not the right result.
My Problem is, that i want to get all content from a table. Each row has to be later like row[0], row[1] .... so i can handle the data. You understand?
//Edit
Ah... i know what you mean.
I removed format(...) and changet the line into:
Код:
formatarray[i] = array[i];
But now in the console, it show wrong.
Example.
In DB:
row 1: lol
row 2: muh
row 3: rofl
It looks in the console now like (LOOK: It start not from first entry - bug?):
r
o
f
l
<null>
<null>
<null>
<null>
<null>
<null>
...
but it must show
lol
muh
rofl
why does it dont show like in the DB?
Re: Array and MySQL -
Nero_3D - 05.07.2009
Try to print the "result" array, it should contain all three words
You just need to find a good way to cut them in to seperate array
If you dont know how, just post the "result" text
Re: Array and MySQL -
KingArthur - 05.07.2009
If i use:
Quote:
stock GetJobData(field[])
{
new tmp[MAX_QUERY];
new result[MAX_QUERY];
new array[50];
format(tmp, sizeof(tmp), "SELECT %s FROM %s", field, JOB_TABLE);
MySQL_query(tmp);
MySQL_result();
while(MySQL_fetch(result))
{
print(result);
}
}
|
i get
No seperator or something like that.
//Edit
And now it must be:
row[0] = lol
row[1] = muh
row[2] = rofl
row[n] = n
Re: Array and MySQL -
Nero_3D - 05.07.2009
try that
pawn Код:
new row[3][30];
for(new i, y, c; result[i] != EOS; i++)
{
if(result[i] == '\r' || result[i] == '\n')
{
if(c)
{
y++;
if(y == sizeof row) break;
c = 0;
}
continue;
}
row[y][c] = result[i], c++;
}
Re: Array and MySQL -
KingArthur - 05.07.2009
Wooow Thank you
I put your code in the include File.
But how can is use now the Funktion GetJobData in the Gamemode?
//Edit
If i put for example this into the GM:
Код:
new row[3][30];
row = GetJobData("spawn_x");
print(row[1]);
it shows nothing in the console.
//Edit
new row[3][30]; // What means 3, i think the 3 entrys in DB, but what 30?
Re: Array and MySQL -
Nero_3D - 05.07.2009
Its an array in an array
I thought again about it, can you try that code maybe :S
I never worked directly with any mysql plugin, so I only guess things
Thats my last try for today
pawn Код:
stock GetJobData(row[][], field[])
{
new result[MAX_QUERY];
format(result, sizeof(result), "SELECT %s FROM %s", field, JOB_TABLE);
MySQL_query(result), MySQL_result();
for(new y; MySQL_fetch(row[y]); y++) {}
}
You use it like
pawn Код:
new row[3][30];
GetJobData(row, "spawn_x");
print(row[0]);
print(row[1]);
print(row[2]);
Re: Array and MySQL -
KingArthur - 05.07.2009
Thank you, thank you very much. That works fine!
Quote:
Originally Posted by ♣ ⓐⓢⓢ
|
Well i know that this is an array in an array. I mean what 3 means and what 30 means. Limits for what? Damn... its hard do explain in english :/
Re: Array and MySQL -
Nero_3D - 06.07.2009
that are the index numbers, they say how much cells the array have
the first array have 3 cells and the second array each 30, the whole array would have 90 cells