Jump to content

heres what i need


h3ktlk

Recommended Posts

right now im using a java script that sets an array..  example below:

 

<script language="Javascript">

var states = new Array("Alabama","Alaska","American Samoa","Arizona","Arkansas","California",

"Colorado","Connecticut","Delaware","District of Columbia",

"Federated States of Micronesia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois",

"Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine",

"Marshall Islands","Maryland","Massachusetts","Michigan","Minnesota","Mississippi",

"Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico",

"New York","North Carolina","North Dakota",

"Northern Mariana Islands","Ohio","Oklahoma","Oregon","Palau","Pennsylvania","Puerto Rico",

"Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont",

"Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming",

"Armed Forces Africa","Armed Forces Americas","Armed Forces Canada",

"Armed Forces Europe","Armed Forces Middle East","Armed Forces Pacific");

new AutoSuggest(document.getElementById('firstname'),states);

</script>

 

can i use php and sql to pull the array and put it in the java ?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/108018-heres-what-i-need/
Share on other sites

<script type="text/javascript">
<?php
  $sql = "SELECT name FROM states ORDER BY NAME";
  $states = array();
  if($result = mysql_query($sql)){
    while($state = mysql_fetch_assoc($result))
      $states[] = $state['name'];
    print 'var states = ["'.implode('","',$states).'];';
    print "\nnew AutoSuggest(document.getElementById('firstname'),states);"
  }
?>
</script>

 

if you are running PHP5+, instead of

    print 'var states = ["'.implode('","',$states).'];';

use  this:

    print 'var states = '.json_encode($states).';';

Link to comment
https://forums.phpfreaks.com/topic/108018-heres-what-i-need/#findComment-553626
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.