get and set a number in a DB

Get help using Construct 2

Post » Wed Nov 20, 2013 8:44 pm

I want to have a single persistent number That does not refresh to a default value when the page is refreshed. I am hosting with goDaddy, and have set up a mySQL DB, and have read some tuts on how to work with it. I want to know how to get and set a number in this DB using C2.
B
22
S
7
G
3
Posts: 41
Reputation: 2,751

Post » Wed Nov 20, 2013 8:52 pm

Add ajax object to project
Add event Ajax post and give tag name (tag ie posttoserver)
Adress needs to be your php file (ie http://yourserver/yourfile.php, paramters added like "request=getdata&somekey=somevar")
Catch $_POST[variable] (if($_POST[request]=="getdata")) with a request for data on the php end
Have php on your server process mysql query based on post request
echo mysl data in your php file
This data is relayed back to your game/application
Use event on request complete (tag ie posttoserver)
This even and subs hold the variable AJAX.Lastdata, which is the information you have echoed in your php file.

Do something with data :)lennaert2013-11-20 20:55:22
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Nov 20, 2013 10:09 pm

Or you can use WebStorage.SetLocal and GetLocal. But a DB has better longer persistency and you can access the data where as webstorage is client side.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Tue Nov 26, 2013 3:55 pm

Can you show me a capx for this where i can add one to a webStorage number when you push a button?
B
22
S
7
G
3
Posts: 41
Reputation: 2,751

Post » Tue Nov 26, 2013 4:04 pm

Actually I do just what you are looking for in my tutorial. The location of the tack is stored and retrieved from the mySQL database.

Click Me
B
10
S
4
G
2
Posts: 41
Reputation: 2,088


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests