row from database to array or...

Get help using Construct 2

Post » Thu Jan 16, 2014 11:29 am

Hi everybody,

I have a frustrating problem about how I can load a single row from my database in my array to set the different value in specific variable in construct2...or with a differen method...

Actually, I can show in contruct2 all of the value from the row in the database like this:

"10""100""300""10""300""...ecc

or:

'10'200'300'400... ecc,

when I load in construct2 with AJAX, I don't know what I can do to use a single row for set all of the variable in construct2...

somebody have some idea? construct2 can recognize a single value from "" for example?

Thank you very much
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Thu Jan 16, 2014 11:39 am

I don't quite understand, but I usually use the separator "|" (without quotes) to separe values on the text, and then using a for loop I can pass this text values to the array using the tokenat to read each value.
Open for Commission, contact email > [email protected]



my personal website with news in my game developer adventure! |

adult ( 18) pixel art games
B
136
S
25
G
21
Posts: 516
Reputation: 25,100

Post » Thu Jan 16, 2014 12:05 pm

from the php file, I can load a value from the database.

when the php file generate the value, I can load in construct2 with AJAX and show the echo in my project.

so, if I use "|", like:

10 | 100 | 1 | 2 |

how i can set the variable in construct2 like this:

healt: 100;
point: 1;
level: 2;

etc..? I don't know how i can do in construct2...

thank you very much

B
21
S
9
Posts: 298
Reputation: 2,967

Post » Thu Jan 16, 2014 12:26 pm

@Ribis - get the text you want with ajax, then separe a value that you want for each variables

example:

1 - Request a text "100|1|2|" from an url using Ajax

2 - On Completed Ajax Request
   - Then set "Healt" variable value to tokenat(AJAX.LastData,0,"|")
   + set "Point" variable value to tokenat(AJAX.LastData,1,"|")
   + set "Level" variable value to tokenat(AJAX.LastData,2,"|")
gillenew2014-01-16 12:28:37
Open for Commission, contact email > [email protected]



my personal website with news in my game developer adventure! |

adult ( 18) pixel art games
B
136
S
25
G
21
Posts: 516
Reputation: 25,100

Post » Sun Jan 19, 2014 8:53 am

[QUOTE=gillenew] @Ribis - get the text you want with ajax, then separe a value that you want for each variables

example:

1 - Request a text "100|1|2|" from an url using Ajax

2 - On Completed Ajax Request
   - Then set "Healt" variable value to tokenat(AJAX.LastData,0,"|")
   + set "Point" variable value to tokenat(AJAX.LastData,1,"|")
   + set "Level" variable value to tokenat(AJAX.LastData,2,"|")
[/QUOTE]

thank you, is working perfectly, with this I make my script better than before, but I have another question, if I have one text like this:

100|20|0|0|0
200|50|20|0|0
90|10|20|20

it's possible to organize the variable for the newline? I mean, with this I have to make 5 text and I made 5 different file in php... if I can use one text line for all of my variable will be perfect, because I will use just one file in php... I can use the same method for one line, but if in the future I add something in my database i need to edit all order, would be a little bit confused...

Thank you very much again Ribis2014-01-19 08:53:53
B
21
S
9
Posts: 298
Reputation: 2,967


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests