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 ? Quote Link to comment 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).';'; Quote Link to comment 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 ... Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.