Trying to get a number from a database into a javascript game.

The javascript below is just a chunk of coding… I need to get the "Seven.Default.Points " number in the javascript to be a number that is pulled from my database. I have php written to pull the number but nothing I do is getting it correct.

PHP:

[code]<?php
$servername = “localhost”;
$username = “username”;
$password = “password”;
$dbname = “database”;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = “SELECT number FROM tablename WHERE username =‘test123’”;
$result = $conn->query($sql);

?>
[/code]

JAVASCRIPT:

[code](function($) {
/**
* Main object for the game
* @type {{}}
*/
var Seven = {};

/**
 * Register other objects
 * @type {{}}
 */
Seven.Default   = {};
Seven.User      = {};
Seven.Game      = {};
Seven.Fn        = {};
Seven.Audio     = {};
Seven.Text      = {};
Seven.Ads       = {};
Seven.Board     = {};

/////////////////////// Seven.Default.Points is what I want to change to pull from the database for that user
Seven.Default.Points = 10; // Points of User
Seven.Default.Bet = 1; // Starting Bet of User
Seven.Default.Percentage = [5, 10, 10, 10, 15, 20, 20]; // Percentage of Images
Seven.Default.AdsTime = 0; // Seconds for Ads to be Visible
Seven.Default.AdsShowTime = 250; // Minutes Between Ads

/**
 * Main object initialization
 */
Seven.init = function() {
    // general buttons for the game
    var minBet = $('#minBet');
    var maxBet = $('#maxBet');
    var Spin   = $('#Spin');

[/code]

do a get request to the server (the fetch number php file) from javascript, jquery has a function to help you with that.

Then in the php file you need to output (echo) the value you want javascript to read/get

Sponsor our Newsletter | Privacy Policy | Terms of Service