
        
  var config = {
    apiKey: "AIzaSyAXNC6VQONyZE_bXOYXuSSF8SN0zCGqiA0",
    authDomain: "test-577be.firebaseapp.com",
    databaseURL: "https://test-577be.firebaseio.com",
    projectId: "test-577be",
    storageBucket: "test-577be.appspot.com",
    messagingSenderId: "776762514468"
  };
  firebase.initializeApp(config);

//ดึงข้อมูลออกมาโชว์
     var database = firebase.database().ref('patients');
             let patients =[]
             let txt ='';


             database.once('value', function (snapshot) {
                txt = '';


                snapshot.forEach(element => {
                    //ส่งตีย์ไปเก็บไว้ด้วยถึงจะเรียกคีย์มาใช้ได้
                    patients.push({key:element.key,value:element.val()})
                    // console.log()
                });
                
                //เอาไปโชว์
                patients.forEach(function (element, index) {
                    txt += " <tr> <th scope=\"row\">" + (index + 1) + "</th><td>" + element.value.Name +
                        "</td> <td>" + element.value.LastName + "</td>";
                    txt += " <td>" + element.value.PhoneNumber + "</td><td>" + element.value.Sex + "</td><td>" +
                        element.value.Age + "</td><td>" + element.value.Service + "</td>"
                    txt += " <td>" + element.value.Detail + "</td><td>" + element.value.Date + "</td><td>" +
                        element.value.Time +
                        "</td><td><button type=\"button\" class=\"btn btn-danger \" id=\"send\" "+
                        "onclick = \"deletePT(\'"+element.key + "\')\">ลบ</button> </td></tr>"
                });
                // console.log(txt);
                //ส่งจจาวาสคริปไปที่html
                document.getElementById("test").innerHTML = txt;

            })

            function deletePT(e) {
                console.log("ลบ");
                console.log(e);
                alert("คุณต้องการที่จะลบใช่หรือไม่");
                firebase.database().ref('patients/'+e).remove()
                location.reload();
            }
  
    
    

