Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - <?php
 - /*declare variable as a result*/
 - $response = array();
 - /*need db_connect.php to connect to database mahasiswa*/
 - include('/db_connect.php');
 - $db = new DB_CONNECT();
 - /*parameter send as get method in a tag name "nama_mhs"*/
 - if(isset($_GET["nama_mhs"]))
 - {
 - /*assigned varible $nama "nama_mhs" which is sent by get method*/
 - $nama = $_GET["nama_mhs"];
 - /*assigned $response with a select result from mysql_query*/
 - $result = mysql_query("SELECT nama_mhs FROM mahasiswa WHERE nama_mhs = '$nama'") or die (mysql_error());
 - /*this if block check whether the $result from query is empty or not*/
 - if(!empty($result))
 - { /*the second if block checked whether the result from $result is greater than one*/
 - if(mysql_num_rows($result) > 0)
 - { /*declare a temporary variable collect result from $result query*/
 - $result = mysql_fetch_array($result);
 - /*declare anew array variable to collect each field from $result*/
 - $specificname = array();
 - $specificname["nama_mhs"] = $result["nama_mhs"];
 - /*success code*/
 - $response["success"] = 1;
 - /*create variable with TAG mahasiswa as an array*/
 - $respone["mahasiswa"] = array();
 - /*put the result from $specificname to TAG mahasiswa*/
 - array_push($response["mahasiswa"], $specificname);
 - /*send result as a json document*/
 - echo json_encode($response);
 - }
 - else
 - { /*a block with no result*/
 - $response["success"] = 0;
 - $response["message"] = "Result is zero";
 - echo json_encode($response);
 - }
 - }
 - else
 - { /*a block with no result*/
 - $response["success"] = 0;
 - $response["message"] = "No match name";
 - echo json_encode($response);
 - }
 - }
 - else
 - { /*a block with no parameter sent*/
 - $response["success"] = 0;
 - $response["message"] = "Require field is missing";
 - echo json_encode($response);
 - }
 - ?>
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment