Ajax Problem!

Get help using Construct 2

Post » Tue Sep 17, 2013 3:45 pm

Hi,

I follow the tutorial the link below.

https://www.scirra.com/tutorials/346/online-high-score-table-ajax-php-mysql

i can save data to database.there is two problem then this point.First my data saves with integrated text like "name1|number1|name2|number2|name3...so is there any way clean previous data ? and if i get data with ajax how can i separate text before and after "|" charecter.

I wait your help.

Regards,guero2013-09-17 15:46:23
B
10
S
3
G
3
Posts: 162
Reputation: 3,190

Post » Wed Sep 18, 2013 5:31 am

Help please :) @ArcadEd
B
10
S
3
G
3
Posts: 162
Reputation: 3,190

Post » Wed Sep 18, 2013 8:10 am

string1 = "name1|number1|name2|number2|name3"

you can get:
name1 by calling "tokenat(string1,0,"|")"
name2 by calling "tokenat(string1,2,"|")"
etc..

tokenat explaination:
https://www.scirra.com/manual/126/system-expressions

To delete from the database, you have to create a new php script to send query to the database to delete what you want to delete as it is not included inside ArcadEd php files.c4sp3r892013-09-18 08:16:26
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Wed Sep 18, 2013 10:12 am

[QUOTE=c4sp3r89] string1 = "name1|number1|name2|number2|name3"

you can get:
name1 by calling "tokenat(string1,0,"|")"
name2 by calling "tokenat(string1,2,"|")"
etc..

tokenat explaination:
https://www.scirra.com/manual/126/system-expressions

To delete from the database, you have to create a new php script to send query to the database to delete what you want to delete as it is not included inside ArcadEd php files.[/QUOTE]

Thansk so much i tried tokenat and it works thanks.bu i dont know how i delete database everry time? please help @ArcadEd

[QUOTE=ArcadEd] Ouote for help [/QUOTE]
B
10
S
3
G
3
Posts: 162
Reputation: 3,190

Post » Wed Sep 18, 2013 10:23 am

While waiting for his reply. You can read up how to delete database entry at here:

http://www.tutorialspoint.com/mysql/mysql-delete-query.htm

You just have to know which query to send to mysql and you can tweak base on the php scripts arcadEd provided.c4sp3r892013-09-18 10:27:14
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Wed Sep 18, 2013 11:02 am

[QUOTE=c4sp3r89] While waiting for his reply. You can read up how to delete database entry at here:

http://www.tutorialspoint.com/mysql/mysql-delete-query.htm

You just have to know which query to send to mysql and you can tweak base on the php scripts arcadEd provided.[/QUOTE]

Thanks so much @c4asp3s89 i can delete all data from example           

Thanks so much again. also sorry ArcadEd

I add my delete code below.

[QUOTE]

<?php
$dbhost = 'localhost';
$dbuser = 'database name';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'DELETE FROM scores
        WHERE score';

$sql = 'DELETE FROM scores
        WHERE name';

$sql = 'DELETE FROM scores
        WHERE id';

mysql_select_db('database name');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
?>

[/QUOTE]

guero2013-09-18 11:03:09
B
10
S
3
G
3
Posts: 162
Reputation: 3,190

Post » Wed Sep 18, 2013 11:11 am

Guero you shouldnt just give c2 an String.

You should better use Arrays.

but ok for deleting just make an new php file with 1 command:

mysql truncate table [tablename]

Edit: Sry you already found a way for that.Darklinki2013-09-18 11:11:39
B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Wed Sep 18, 2013 11:14 am

Glad that you got it work out. However there's some problem on this script.

Line1: $sql = 'DELETE FROM scores
               WHERE score';

Line2: $sql = 'DELETE FROM scores
               WHERE name';

Line3: $sql = 'DELETE FROM scores
               WHERE id';

$retval = mysql_query( $sql, $conn );

Doing so will only send query of Line3 to server. which actually Line 1&2 is useless. You can google up MySQL query to read up on how to combine things like "DELETE FROM scores WHERE score=100 AND name='me' AND id=1".
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Wed Sep 18, 2013 2:59 pm

[QUOTE=c4sp3r89] [/QUOTE]

Yes Thanks i understand but now it works fine as i want no problem. i will not use this feature for score or any game option i think use with geolation

[QUOTE=Darklinki] [/QUOTE]

Thanks for interest   
B
10
S
3
G
3
Posts: 162
Reputation: 3,190

Post » Wed Sep 18, 2013 4:36 pm

Glad you got it.

I am no PHP expert by any means. In fact it's been several years since I did any real PHP programming so I am glad others were able to help.

Also weird that I never got notified that I was tagged in this post. Weird.
B
100
S
32
G
11
Posts: 1,552
Reputation: 21,612

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 6 guests