PHP arrays to JavaScript -


this question has answer here:

i searching in page answer question, dont found it.

<script type="text/javascript">  var jsarray=     []; <?php  include("conectar.php");      if (isset($_get['selector'])) $condicion = ' clave=' . $bd->quote($_get['selector']);     else $condicion = '';      $pet = $bd->prepare("select * calendario" . $condicion);     $pet->execute();     $filas = $pet->fetchall();     $arrayf=array();     $arrayu=array();     print '<table class="gridtable">';     foreach ($filas $fila)      {         //print '<tr><td>'.$fila['fecha'] . '</td><td>' . $fila['url'] . '</td></tr>';         array_push($arrayf,$fila['fecha']);         array_push($arrayu,$fila['url']);     } ($i=0 ;$i < count($arrayf); $i++){     echo 'jsarray['.$i.'] = "'.$arrayf[$i].'";'; }  ?>   window.onload=function(){  alert(jsarray); }  </script> 

i accesing database, getting data , the, putting arrayf , arrayu. then, have send array javascript work them. dont work. dont know why, when execute it, dont show me nothing, arrays in php elements, sure of this, beacause

anyone knows why occurs this?

you can use json_encode function that. can find simple examples here.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -