0

Possible Duplicate:
pass php array to javascript function
Pass PHP array into Javascript array

I got problem pass the PHP data to Javascript. I need to transfer the addr column to array then pass array to Javascript , how can i fetch it out of PHP then use array in Javascript? thank you

<?php
  require_once 'Common/system_start.php';
  $sql="select addr from tab_mem order by sn desc ";
  $result=  mysql_query($sql);
  $data=mysql_fetch_assoc($result);
  $row=mysql_num_rows($result);
  $n = array(); 
  for($i=0;$i<$rows;$i++) 
  { 
   $data=mysql_fetch_row($result); 
   $n[i] = $data[i]; 
  } 

  ?>
Community
  • 1
  • 1
  • Is this an API to which the js connects to, to get data, or does this php script output a page with javascript? – Ahatius May 08 '12 at 06:36
  • no, this my PHP code, I wish people can help me out to get the var from it. :-) – Shuyou Chang May 08 '12 at 06:38
  • Question was closed. I didn't ask if it's your code, I just wanted to know which way you want the data. AJAX call to php script or does the php script output the complete html code including javascript. – Ahatius May 08 '12 at 06:42
  • Probably you will need an ajax call to get the array from php – Moyed Ansari May 08 '12 at 06:46
  • I am so sorry I was misunderstanding. I need to fetch the Address data from database then pass it to my Geocoder for google map. I don't know which way is the best way to do it. thanks for your asking. – Shuyou Chang May 08 '12 at 06:51
  • how can I use the Ajax to call the array, I did try for few days, but I cannot do anything!!!! – Shuyou Chang May 08 '12 at 07:06

1 Answers1

0

Try:

<script>
var jsArray = ["<?php echo join("\", \"", $n); ?>"];
alert(jsArray);
</script>
botheredbybees
  • 582
  • 6
  • 14