PHP MySQL Select2 Dropdown Example

Feb 28, 2022 . Admin

Hello Friends,

I am going to explain you php mysql select2 example. You will learn php mysql select query example. In side this article we will see php example select from MySQL. Select2 is a widely used jQuery plugin. It makes select elements user-friendly.

This article will give you simple example of how to php mysql select2 example drop down list with core php mysql. We will use get search how to php mysql select2 example drop down list.

You can use from how to use select2 in php. I will give you simple mysql select examples query.

So, let's see bellow solution:

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHP MySQL Select2 Example</title>
    <link rel="stylesheet" href="" integrity="sha256-aAr2Zpq8MZ+YA/D6JtRD3xtrwpEz2IqOS+pWD/7XKIw=" crossorigin="anonymous" />
    <script src="" integrity="sha256-OFRAJNoaD8L3Br5lglV7VyLRf0itmoBzWUoM+Sji4/8=" crossorigin="anonymous"></script>
    <script src=""></script>
    <link href="" rel="stylesheet" />
    <script src=""></script>
<div class="row mt-5">


        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "db_php";

        $conn = new mysqli($servername, $username, $password, $dbname);

        $sql = "SELECT * FROM `post`";

        $result = $conn->query($sql);


        <div class="col-md-6 offset-3 mt-5">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h4>PHP MySQL Select2 Example -</h4>
                <div class="card-body" style="height: 280px;">

                        <select class="select2 form-control" data-rel="chosen"  name="degree_id" id="selectError">
                                while ($row = $result->fetch_assoc()) {
                                    echo "<option>".$row["title"]."</option>";


    <script type="text/javascript">

It will help you...