-3

I have posted a similar topic before and didn't get a answer that worked. Properly because my question was lacky. I will try again more specific. Im working on a bracket system plugin.

The plugin works like this:

var bigData = {
teams : [
    ["Team 1",  "Team 2" ],
    ["Team 3",  "Team 4" ],
    ["Team 5",  "Team 6" ],
    ["Team 7",  "Team 8" ],
    ["Team 9",  "Team 10"],
    ["Team 11", "Team 12"],
    ["Team 13", "Team 14"],
    ["Team 15", "Team 16"]
};

You have to manually type the name of the team. I created a push array to create the teams in a for loop:

 var bigData = {
"teams" : [],
"results" : [] };

for( var i=1 ; i<16 ; i+=2 )
   { 
    bigData.teams.push(["Team "+i,"okay"
    ]);
}

The problem is this: i really like to pass in data from php to the teams: i can use mysql, and pass in the team names from a database. The code just wont work! - No matter what i do, u can't pass in <?php ?>:

bigData.teams.push(["<?php echo 'somethinghere' ?>",'Team '+(i+1)]);

The images looks like this, when there is no <php ?>

https://i.stack.imgur.com/zB6eS.jpg

I can't post two links.. but it's just empty

I hope this is detailed enough to get an understanding of my problem! Thanks

Pavel S.
  • 11,892
  • 18
  • 75
  • 113
Emil
  • 21
  • 4
  • 1
    Where is your PHP, man? – Pavel S. Jan 31 '14 at 23:56
  • 1
    Have you considered [json_encode](http://www.php.net/json_encode)? – ferdynator Jan 31 '14 at 23:57
  • 1
    Asking the same questions again? http://stackoverflow.com/questions/21470541/php-in-javascript-is-it-possible. The answer you got there is good. – Will Feb 01 '14 at 00:00
  • Please don't repost the same question. If you believe the previous answers were inadequate, please post comments below them to explain why they don't address your question. If you want to modify your question to make it clearer and/or add information, please click the grey "edit" link below the question. – Adi Inbar Feb 01 '14 at 03:19

1 Answers1

0

Here are some steps to take:

  1. Make sure you're only putting PHP code in a .php file
  2. Use an on-page <script> tag or an AJAX/JSON request.

example: Use json_encode:

File: data.php

<?php
echo json_encode( $my_array );

File read_data.js

$.getJSON( 'data.php', function(data){
    bigData.teams.push( data );
});
redolent
  • 4,159
  • 5
  • 37
  • 47