second-level data withdrawal json through jqery



  • I get every three seconds json a set of two levels. 1 level is normal, and the second level cannot be removed, written always by Array.

    function loadplace () {
        $.post( "php/loadplace.php",
            function(data){
                $('#playersonair').html('Собрались: ');
                for (var i = 0; i < data.onair[0].length; i++) { $('#playersonair').append(data.onair[0][i] + ', '); }
            }, "json" );
    }
        setInterval(loadplace,3000);
    

    In the php somewhere at the beginning, $nam1 and 2 and then the code:

    $result = mysql_query ("SELECT * FROM onair" ,$db);
    $i=0; while ($myrow = mysql_fetch_array ($result)) {
        $user =$myrow[userid];
        $result2 = mysql_query ("SELECT name FROM users WHERE id='$user' " ,$db);
        $myrow2 = mysql_fetch_array ($result2);
        $onair[$i] = $myrow2[name]; $i++;
    }
    

    echo json_encode(array("name1"=>"$name1","name2"=>"$name2", "onair"=>"$onair"));

    I'm finally writing, "I've got it," that's, like, "I'm writing the first letter of the word "A"
    I'd like, "I'd like to get it: %username%, %username%, %username%,"



  • Turns out I didn't put the second level of the json through the php, I had to write a array instead of the $onair. In the php file, the last line was supposed to look like this:

        $forecho = array("name1"=>"$name1","name2"=>"$name2", "onair"=>array($onair));
    echo json_encode($forecho);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2