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

Hello

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

Thanks
B
4
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 0.0.0.0"; // 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";

$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
echo $rows['id'] . "|";
}

// close MySQL connection
mysql_close();
?>


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
B
47
S
14
Posts: 253
Reputation: 5,389


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 6 guests