How do I get result of sql query with ajax in contruct 2?

Get help using Construct 2

Post » Sat Oct 10, 2015 5:26 am


I have a Php file that make a query like

$query = "SELECT score FROM users where id = '$ID'";
$result = mysql_query($query);

result should to return a number.

How can i get the result with ajax to operate or compare in construct 2?

I try with ajax.lasdata, but not works

Posts: 50
Reputation: 290

Post » Sat Oct 10, 2015 12:43 pm

Firstly , Your php, should look like this,
header('Access-Control-Allow-Origin: *');
$host="your host i.e"; // Host name
$username="your username"; // Mysql username
$password="your password"; // Mysql password
$db_name="the database name"; // Database name
$tbl_name="your table name"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database
$sql="SELECT * FROM your table name ORDER BY id DESC LIMIT 300";


// Start looping rows in mysql database.
echo $rows['id'] . "|";

// close MySQL connection

Then you should be able to access the ajax.lastdata, make sure it shows up in the debugger.
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
Posts: 260
Reputation: 5,493

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 39 guests