Taking Mysql Data Using Php and Passing to Javascript

Asked

Viewed 197 times

1

I’m using that code:

<?php
    include '../config/config.php';

    if($_POST['type'] == 'load_url')
    {
        $id = (int) $_POST['id'];
        $sql = mysql_query("SELECT * FROM players WHERE id='$id'");
        $item = mysql_fetch_array($sql);

        $dados['link'] = $item['link'];

        $nome_extra = json_decode($item['nome_extra']);
        $link_extra = json_decode($item['link_extra']);

        for($i_extra = 0; $i_extra < count($nome_extra); $i_extra++)
        {
            $dados['link_extra'][$i_extra] = $link_extra[$i_extra];
        }

        echo json_encode($dados);
        exit;
    }

    $id = (int) $_GET['id'];
    $sql = mysql_query("SELECT * FROM players WHERE id='$id'");
    $item = mysql_fetch_array($sql);
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>CinePopHD | Player</title>
  <script src="https://www.cinepophd.com/media/bower_components/angular/angular.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/angular-translate/angular-translate.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/jquery/dist/jquery.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/jquery-mousewheel/jquery.mousewheel.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/mousetrap/mousetrap.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/angularjs-slider/dist/rzslider.min.js"></script>
  <script src="https://www.cinepophd.com/media/bower_components/streama-i18n/dist/streama-i18n.min.js"></script>
  <script src="https://www.cinepophd.com/media/dist/streama-video-player.js"></script>
  <link rel="stylesheet" href="https://www.cinepophd.com/media/bower_components/Ionicons/css/ionicons.css">
  <link rel="stylesheet" href="https://www.cinepophd.com/media/bower_components/angularjs-slider/dist/rzslider.css">
  <link rel="stylesheet" href="https://www.cinepophd.com/media/dist/streama-video-player.css">

  <style>
    body{
      background: black;
    }
  </style>
</head>
<body oncontextmenu="return false">
<body ng-app="myModule">


  <streama-video-player options="$root.videoOptions">
  </streama-video-player>


  <script type="text/javascript">
    angular.module('myModule', ['streama.videoPlayer']).run(function ($rootScope) {
        $rootScope.videoOptions = {
        videoSrc: '',
        isExternalLink: true,
        videoMetaTitle: 'Jovens Titãs',
        videoMetaSubtitle: 'O Contrato de Judas',
        videoMetaDescription: 'O filme não deve adaptar literalmente o arco The Judas Contract, mas apenas se inspirar na história, onde os Titãs enfrentam a traição da personagem Terra, que se une ao Exterminador para acabar com a equipe. Jay Oliva, também de Liga da Justiça Sombria, dirige e não há data de lançamento.',
        showNextButton: false,
        episodeList: {
            1: [
                        {id: 1, name: 'Temporada 1: Ep.1 "Piloto"', season_number: 1, episode_number:1, episodeString: 'Temporada 1: Ep.1', overview: 'Barry acorda do coma e usa sua nova e extraordinária velocidade para combater outro meta-humano que usa poderes meteorológicos para assaltar bancos.'},
                        {id: 2, name: 'Temporada 1: Ep.2 "O Homem Mais Rápido do Mundo', season_number: 1, episode_number:2, episodeString: 'Temporada 1: Ep.1', overview: 'Barry enfrenta diversos assassinos que invadem a premiação onde ele acompanha Iris, mas os efeitos colaterais de seus novos superpoderes representam uma ameaça.'}
          ]
        },
                showEpisodeBrowser: false,
                currentEpisode : {
                    episode: 1,
                    season: 1
                },
      }

        });



  </script>
</body>
</html>

But I don’t know how to adapt $data['link'] = $item['link']; Ali on videoSrc: ''

1 answer

0

You can put:

echo "
<script>
    var dados = JSON.parse('".json_encode($dados)."');
</script>";

And then use javascript as data

Browser other questions tagged

You are not signed in. Login or sign up in order to post.