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]; 
  } 

  ?>
6
  • Is this an API to which the js connects to, to get data, or does this php script output a page with javascript? Commented May 8, 2012 at 6:36
  • no, this my PHP code, I wish people can help me out to get the var from it. :-) Commented May 8, 2012 at 6: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. Commented May 8, 2012 at 6:42
  • Probably you will need an ajax call to get the array from php Commented May 8, 2012 at 6: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. Commented May 8, 2012 at 6:51

1 Answer 1

0

Try:

<script>
var jsArray = ["<?php echo join("\", \"", $n); ?>"];
alert(jsArray);
</script>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.