PHP变量用于游戏的Javascript代码

时间:2016-07-14 14:08:42

标签: javascript php bitcoin

<script>
        $(document).ready(function(){
                 var oMain = new CMain({
                                win_occurrence:30,        //WIN    PERCENTAGE.SET A VALUE FROM 0 TO 100.
                                slot_cash: 2000000,          //THIS IS THE CURRENT SLOT CASH AMOUNT. THE GAME CHECKS IF THERE IS AVAILABLE CASH FOR WINNINGS. THIS SHOULD BE BALANCE OF MY OVERALL BTC ACCOUNT.
                                min_reel_loop:2,          //NUMBER OF REEL LOOPS BEFORE SLOT STOPS  
                                reel_delay: 6,            //NUMBER OF FRAMES TO DELAY THE REELS THAT START AFTER THE FIRST ONE
                                time_show_win:2000,       //DURATION IN MILLISECONDS OF THE WINNING COMBO SHOWING
                                time_show_all_wins: 2000, //DURATION IN MILLISECONDS OF ALL WINNING COMBO
                                money:<?php include 'getbtcbalance.php'; echo $btcbalance;?> ,               //STARING CREDIT FOR THE USER - THIS IS GOING TO BE AN ECHO OF USER ADDRESS BALANCE.. So 'getbalance of addressofsessionidvariable'
                                ad_show_counter:3    

(在此之后没有必要看到工作正常)

正如你所看到的,我试图让'money:'部分成为来自getbtcbalance.php文件的名为$ btcbalance的php变量。

php变量$ btcbalance在getbtcbalance.php上工作正常,可以回显显示正确的平衡,我只需要在js脚本中使用它。

我上面做的不起作用,我把它留在那里,这样你就可以看到我正在做的事情。

希望有人可以提供帮助。

编辑:

根据要求附加了getbtcbalance.php的内容:

<?php

    // Getting BTC address from database by using a post function 'selecting row of session username' 
//Set btc address as a ssession variable so that it can be used for topup
include_once 'blockconfig.php';
session_start();

$connect=mysqli_connect('localhost', 'root', 'PASSWORD') or die(mysqli_error());
mysqli_select_db($connect, 'test6') or die("Cannot select database");

$sessionusername = $_SESSION['username'];
$res2 = mysqli_query($connect, "SELECT * FROM test WHERE username='$sessionusername'");
if (!$res2) {
printf("Error: %s\n", mysqli_error($connect));
exit();
}
$row=mysqli_fetch_array($res2);

$bitty = $row['btcaddress'];
$_SESSION['btcaddress'] = $bitty;
$btcbalancedetails = $block_io->get_address_balance($bitty);
$btcbalance = "".$btcbalancedetails->data->available_balance."";
// Do below if you need to echo the address on this page, or you can copy / paste it onto another page to echo the btc address

// if (isset($bitty)){

//   echo $sessionusername."'s BTC address for TOP-UP: ".$bitty;}
//    else { 
//            echo mysqli_error($connect);
// }


?>

2 个答案:

答案 0 :(得分:1)

您可以在html代码之前包含php文件,然后使用php文件变量。

<?php include 'getbtcbalance.php';?>
<script>
        $(document).ready(function(){
                 var oMain = new CMain({
                                win_occurrence:30,        //WIN    PERCENTAGE.SET A VALUE FROM 0 TO 100.
                                slot_cash: 2000000,          //THIS IS THE CURRENT SLOT CASH AMOUNT. THE GAME CHECKS IF THERE IS AVAILABLE CASH FOR WINNINGS. THIS SHOULD BE BALANCE OF MY OVERALL BTC ACCOUNT.
                                min_reel_loop:2,          //NUMBER OF REEL LOOPS BEFORE SLOT STOPS  
                                reel_delay: 6,            //NUMBER OF FRAMES TO DELAY THE REELS THAT START AFTER THE FIRST ONE
                                time_show_win:2000,       //DURATION IN MILLISECONDS OF THE WINNING COMBO SHOWING
                                time_show_all_wins: 2000, //DURATION IN MILLISECONDS OF ALL WINNING COMBO
                                money:<?php echo $btcbalance;?> ,               //STARING CREDIT FOR THE USER - THIS IS GOING TO BE AN ECHO OF USER ADDRESS BALANCE.. So 'getbalance of addressofsessionidvariable'
                                ad_show_counter:3    

答案 1 :(得分:0)

您正在回显页面加载时的余额,是否确定在加载页面后它会相同。

它是常数值然后尝试这个 -

money:'<?php echo $btcbalance;?>'