Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Thursday, January 18, 2018

How To Populate JSON Data In Select Dropdown Using jQuery?

ViewUserData.php


<?php

$DatabaseServer = "localhost";

$DatabaseUsername = "root";

$DatabasePassword = "root";

$DatabaseName = "demo";


$Connection = mysqli_connect($DatabaseServer , $DatabaseUsername ,  $DatabasePassword , $DatabaseName);

 

if($Connection=== false){

    die("ERROR: Could not connect. " . mysqli_connect_error());

}


$SQL = mysqli_query($Connection, "SELECT * FROM User");

$Result = array();


while($Row = mysqli_fetch_assoc($SQL))    {

       $Result[] = array(

          'FirstName' => $Row['FirstName']            

       );

    }


    echo  json_encode($Result);

?>


Output:

JSON Array:



[{"UserID":"1","FirstName":"Ram","LastName":"Sri"}]


ViewUserData.html


<Html>

<head>

<script language="JavaScript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<script>

$(document).ready (function () {

            $.getJSON ("ViewUserData.php",

                function (json) {

                    for (var i = 0; i < json.length; i++) {

                        $("#UserID").append("<option>" + json[i].FirstName+ "</option>");

                    }

                });

});

</script>

</head>


<body>


<select id='UserID'>

//Your Json Array comes here
</select>


</body>


</html>


Output:










MySQL: Run these two queries


CREATE TABLE `user` (
  `UserID` int(12) NOT NULL,
  `FirstName` varchar(48) NOT NULL,
  `LastName` varchar(48) NOT NULL,
  `Email` varchar(128) NOT NULL,
  `City` varchar(48) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `user` (`UserID`, `FirstName`, `LastName`, `Email`, `City`) VALUES
(1, 'Ram', 'Sri', 'zzz@zzz.com', 'Delhi'),
(2, 'Krishna', 'Vasudev', 'yyy@yyy.com', 'Delhi');

31 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Buy perfect money in India @Rs.70/- per pm Sell @Rs.58/- per pm,CALL 08054019105, Chandigarh, 160017

    --------------------------------------------------------------------------------------------------------------

    Buy/Sell Perfect Money At Reasonable Rates. We Provide Perfect Money At best Rates.
    We also sell buy Perfect Money, neteller and Bitcoin.

    Call us : +91 9517544444

    Gtalk : garrysingh1598

    Web.: www.sellperfectmoney64.com

    ReplyDelete
  3. Most of the students who look for an academic writing solution simply search for such on a site on the most widely used search engine and select anyone firm from the top websites there.But little do they know that going through a review of such websites will give you much insight about it which you can’t know by simply visiting it.
    All Assignment Help review

    ReplyDelete
  4. Thanks for the great writeup. This the fact is once were some sort of pleasure bank account this.Commercial Led Lighting

    ReplyDelete
  5. June Florist - Same day flower delivery singapore. Call June Florist for floral arrangements for wedding, decorations for conferences, hand banquet decorations, Flower Box, table flower arrangement & more. Tel: +65 6282 7555
    online flower shop singapore
    online flower delivery

    ReplyDelete
  6. Lighting Warehouse Sydney Eye-catching element of written content. I merely came across your own web site and accession capital to say that we receive essentially liked account your current blog page discussions

    ReplyDelete
  7. Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
    Webdesining course in chennai

    ReplyDelete

  8. Hi guys, It’s always the first and important step for electric-guitar-beginners to get their first “right” BEST electric guitar. Because that guitar will follow us through our first stage in the guitar world. You know that since you’re reading this topic and haven’t yet picked a guitar randomly in a store, on the internet or recommended by some friends.

    if you want more just look here Studio Microphone

    ReplyDelete
  9. Blog của bạn all posts messages is very exclusive and good for the user because when you have read your blog look the symbol is not allowed for me. I want to thank thank you. Most priority is you have a bookmark your web to update the future.
    hotmail login

    ReplyDelete
  10. This is really great work. Thank you for sharing such a good and useful information here in the blog.

    Are you using roadrunner mail service or facing Roadrunner Email Problems and want help. just dial our customer service number +1-888-338-6033

    ReplyDelete
  11. I want to say thanks to you. I have bookmark your site for future updates.
    Kindle won't connect to wifi

    ReplyDelete
  12. Thanks for a marvelous posting! I actually enjoyed reading it, you can be a great author.I will be sure to bookmark your blog and definitely will come back later on. I want to encourage you to definitely continue your great job, have a nice afternoon! digital marketing trends

    ReplyDelete
  13. Hey would you mind letting me know which web host you're working with? I've loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most. Can you suggest a good hosting provider at a reasonable price? Thanks, I appreciate it!Amaron Inverter in Chennai

    ReplyDelete
  14. Java Assignment Help
    Many times students are tensed for their projects and assignments, so at that time they can take online assignment help to complete it on time. There are experts available online who prepare the perfect assignment for you.

    ReplyDelete
  15. you can go through AllAssignmentHelp reviews. It will help you to know about the services, and it will help you to know whether that site is reliable or not. This is a way of understanding the opinion of users, and it helps the website to maintain its functionality and reliability.

    ReplyDelete
  16. Thanks for sharing about "How To Populate JSON Data In Select Dropdown Using jQuery?" Your post is really helpful for PHP users. I hope you will share another post for your readers.
    Kindle Fire Wifi Connection Failure

    ReplyDelete
  17. Thank you for sharing this resource with me and the world. Wish you always luck.AllAssignmenthelp.com reviews

    ReplyDelete
  18. Office.com/Setup is a set of desktop applications, which is widely used products for the home as well as an office. Microsoft office gives the freedom of writing documents, blogs, letters and with the use of Microsoft office PowerPoint one can prepare a presentation also.

    howtominernewswatt
    Norton.com/Setup
    Office.com/Setup
    Office.com/Setup
    office Setup
    Daily Helps
    office.com/Setup

    ReplyDelete
  19. Office Setup is a software which is used by almost all company and business and even by individuals For all their office activities or for personal use. It has excels, word, and ppt as their constituent are most widely used apps. For any concern and help just visit website for office help and key activation. You can do it by yourself if you know how to install office setup on your PC or Mac or you can call third party companies as well who can do it on your behalf.
    office.com/Setup
    office.com/Setup
    Norton.com/Setup
    office.com/Setup
    office.com/Setup
    office.com/Setup
    Norton.com/Setup

    ReplyDelete
  20. Assignment writing services are providing our experts. Fully guide and help writer your assignment. Our experts are available anytime helping you. Direct hire at our website australiaasignmenthelp.com

    ReplyDelete

More Posts

FOLLOW