h3ktlk Posted May 30, 2008 Share Posted May 30, 2008 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 More sharing options...
rhodesa Posted May 30, 2008 Share Posted May 30, 2008 <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 More sharing options...
h3ktlk Posted May 30, 2008 Author Share Posted May 30, 2008 when i do this.. it doesnt display the page.. error ... Link to comment https://forums.phpfreaks.com/topic/108018-heres-what-i-need/#findComment-553662 Share on other sites More sharing options...
h3ktlk Posted May 30, 2008 Author Share Posted May 30, 2008 actually i fixed that.. but it doesnt pull from the database. Link to comment https://forums.phpfreaks.com/topic/108018-heres-what-i-need/#findComment-553664 Share on other sites More sharing options...
fenway Posted May 30, 2008 Share Posted May 30, 2008 actually i fixed that.. but it doesnt pull from the database. Are you sure? Link to comment https://forums.phpfreaks.com/topic/108018-heres-what-i-need/#findComment-553801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.