javascript - JS - Can't send php to js variable -


this question has answer here:

i'm working on gchart organization. in php able , echo text db.

here have problem on how pass text db js. in here, have text db ($data[nama] , $data[parnama] ), want use in js=>['$data[nama]', '$data[parnama]', null],

how can that?

big help.

update

<?php         $host="localhost";         $user="root";         $pass="";         $dbnama="skripsi";         mysql_connect($host, $user, $pass) or die ("database tidak dapat di akses");         mysql_select_db($dbnama);          $query="select * tblarya";         $hasil=mysql_query($query);     if($hasil === false) {             die(mysql_error());          }          while ($data=mysql_fetch_array($hasil)){              echo "<label>$data[nama]</label>&nbsp;<label>$data[parnama]</label><br>";}         ?>          <html xmlns="http://www.w3.org/1999/xhtml">           <head>             <meta http-equiv="content-type" content="text/html; charset=utf-8"/>             <title>testing</title>             <script type="text/javascript" src="http://www.google.com/jsapi"></script>             <script type="text/javascript">               google.load("visualization", "1", {packages: ["orgchart"]});               function drawvisualization() {                      var data = google.visualization.arraytodatatable([           //assign row db js            //for (record 1 upto allrow text in db)                   ['$data[nama]', '$data[parnama]', null], ]);                  // create , draw visualization.                 new google.visualization.orgchart(document.getelementbyid('visualization')).                     draw(data, {allowhtml: true});               }         google.setonloadcallback(drawvisualization);             </script>           </head>           <body style="font-family: arial;border: 0 none;">             <div id="visualization" style="width: 300px; height: 300px;"></div>           </body>         </html>         <html>         <body> 

sql

-- phpmyadmin sql dump -- version 3.2.4 -- http://www.phpmyadmin.net -- -- host: localhost -- waktu pembuatan: 17. juli 2013 jam 22:08 -- versi server: 5.1.41 -- versi php: 5.3.1  set sql_mode="no_auto_value_on_zero";   /*!40101 set @old_character_set_client=@@character_set_client */; /*!40101 set @old_character_set_results=@@character_set_results */; /*!40101 set @old_collation_connection=@@collation_connection */; /*!40101 set names utf8 */;  -- -- database: `skripsi` --  -- --------------------------------------------------------  -- -- struktur dari tabel `tblarya` --  create table if not exists `tblarya` (   `nama` text not null,   `parnama` text not null ) engine=myisam default charset=latin1;  -- -- dumping data untuk tabel `tblarya` --  insert `tblarya` (`nama`, `parnama`) values ('a', '-'), ('b', 'a'), ('c', 'a'), ('d', 'b'), ('e', 'b');  /*!40101 set character_set_client=@old_character_set_client */; /*!40101 set character_set_results=@old_character_set_results */; /*!40101 set collation_connection=@old_collation_connection */; 

you need echo them javascript variable. i'm not sure why want null value though.

here's code.

<script type="text/javascript">   var data = ['<?php echo $data['nama'] ?>',               '<?php echo $data['paranama'] ?>',               null]; </script> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -