0 Favourites

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

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)