Create array from MYSQLI table in PHP and pass to JAVASCRIPT to allow autocomplete on form

I am using Bootstrap and I want to populate a PHP variable array using a MYSQL table value and then pass the array to a JAVASCRIPT variable to be able to use autocomplete but I just cannot get it to work. I know the PHP array is populated but I cannot see if the JAVASCRIPT variable is set up. Below is my code (excluding the call to the database)


$query1 = "SELECT country_code FROM country";
            $result1 = mysqli_query($mysqli,$query1);
            if ($result1) { 
                $count = mysqli_num_rows($result1);
            while( $row1 = mysqli_fetch_assoc( $result1)){
                $addr_a[] = $row1['country_code']; 
    <script type="text/javascript">
            var addr_aray= <?php echo json_encode($addr_a); ?>;
            for(var i = 0; i < addr_aray.length; i++){
                document.getElementById("demo").innerHTML = addr_aray;

161 thoughts on “Create array from MYSQLI table in PHP and pass to JAVASCRIPT to allow autocomplete on form”

  1. It’s perfect time to make a few plans for the long run and
    it’s time to be happy. I have read this publish and if I may I want to
    recommend you few attention-grabbing things or advice.
    Perhaps you can write next articles relating to this article.
    I want to read more issues approximately it!

  2. I’m truly enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out
    a designer to create your theme? Great work!

  3. Hey I know this is off topic but I was wondering if you knew
    of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you
    would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  4. Appreciating the time and effort you put into your blog and detailed information you provide.
    It’s good to come across a blog every once in a while that isn’t
    the same outdated rehashed information. Excellent
    read! I’ve bookmarked your site and I’m adding your RSS
    feeds to my Google account.

  5. Pingback: viagra canada
  6. Pingback: cheap viagra
  7. Pingback: cialis oral
  8. Pingback: viagra alternative
  9. Pingback: buy cialis 20mg
  10. Pingback: gay dating phoenix
  11. Pingback: canadian viagra
  12. Pingback: sildenafil online
  13. Pingback: buy generic viagra
  14. Pingback: cialis samples
  15. Pingback: 25mg viagra price
  16. Pingback: viagra and cialis
  17. Pingback: teva tadalafil
  18. Pingback: sildenafil 20mg

Leave a Comment