[HELP] API KEY PHP, JSON, JQUERY

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Grandong
Forum Commoner
Posts: 65
Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:

[HELP] API KEY PHP, JSON, JQUERY

Post by Grandong »

hi
I'am Happy Registration to this forum.
I hope I can add knowledge about programming.

Ok, I'm working on a project Flight Search Engine With the API Key.
is there any users here who have already worked on this kind of project?
----
So ... This is My Question:

1. I use curl to get data from API
2. then my json result with javascript process.

This My PHP Code

Code: Select all

<?php
$Asal = "";
$Tujuan = '';
$Tanggal = '';
$Dewasa = '';
$Anak = '';
$Bayi = '';

if(isset($_GET['asal']) || isset($_GET['tujuan']) || isset($_GET['tanggal']))
{
	$Asal = $_GET['asal'];
	$Tujuan = $_GET['tujuan'];
	$Tanggal = $_GET['tanggal'];
	$Dewasa = $_GET['dewasa'];
	$Anak = $_GET['anak'];
	$Bayi = $_GET['bayi'];
}
$Token = "xxxxxxxxxxxxxxxxxxxxxxxxx"; //Isi Token Anda Disini

//$Data = file_get_contents("https://api.master18.tiket.com/search/flight?d=".$Asal."&a=".$Tujuan."&date=".$Tanggal."&adult=1&child=0&infant=0&ret_date=&token=".$Token."&output=json");


/****************************INI YANG SAYA TAMBAHKAN DI FILE tiket.php**************************/

$url = "https://api.master18.tiket.com/search/flight?d=".$Asal."&a=".$Tujuan."&token=".$Token."&output=json&adult=".$Dewasa."&child=".$Anak."&infant=".$Bayi."&sort=priceasc&v=3&ret_date=&date=".$Tanggal;

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //bypass the ssl certificate

$Data = curl_exec($ch); //get contents

$error = curl_error($ch); //get errors

// close cURL resource, and free up system resources
curl_close($ch);

//var_dump($error); //dumping variable
/*******************************SAMPAI SINI*****************************************************/
?>
Then, This My HTML

Code: Select all

<html>
<head></head>
<body>
<link href="css/jquery-ui.css" type="text/css" rel="stylesheet" />
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(document).ready(function() {
	
	$('#datepicker').datepicker({ dateFormat: "yy-mm-dd" });
	
    $('#submit').click(function(event) {
        $('#result').html('Tunggu Bentar Ya.. ^_^ ');
        var FormData = $('#FormTiket').serialize();
        event.preventDefault();
        $.ajax({
            type : "GET",
            url:'http://localhost/1/tiket.php',
            data: FormData,
            cache: false,
        }).done(function(data){
			if(data==''){
				$('#result').empty();
				$('#result').html('Maaf, data tidak ada untuk rute ini.');
			}else{
				$('#result').empty();
				var div = $("#result");
				data = JSON.parse(data);
				for(var i=0; i<data.departures.result.length;i++){                       
					div.append("Flight ID : "+data.departures.result[i].flight_id+"<br>");
					div.append("Nama Airlines : "+data.departures.result[i].airlines_name+"<br>");
					div.append("No. Penerbangan : "+data.departures.result[i].flight_number+"<br>");
					div.append("Harga Tiket : "+data.departures.result[i].price_value+"<br>");
					div.append("Jam Berangkat : "+data.departures.result[i].simple_departure_time+"<br>");
					div.append("Jam Tiba : "+data.departures.result[i].simple_arrival_time+"<br>");
					div.append("Durasi Perjalanan : "+data.departures.result[i].duration+"<br>");
					div.append("Gambar : <img src='"+data.departures.result[i].image.replace('https','http')+"' /><br>");
					div.append('<a href="select.php?id='+data.departures.result[i].flight_id+'&token='+data.token+'&tanggal='+data.departures.result[i].date+'">Test link</a> <br>'); 
					div.append("<hr>");           
				}  
			}
		})
    });
});
</script>
<form id="FormTiket" name="FormTiket">
<table>
    <tr>
        <td>Kota Asal</td>
        <td>:</td>
        <td>
        <select id="asal" name="asal">
            <option value="CGK">Jakarta</option>
            <option value="BTH">Batam</option>
            <option value="DPS">Denpasar</option>
         </select>
        </td>
    </tr>
    <tr>
        <td>Kota Tujuan</td>
        <td>:</td>
        <td>
        <select id="tujuan" name="tujuan">
            <option value="DPS">Denpasar</option>
            <option value="AMQ">Ambon</option>
            <option value="BPN">Balikpapan</option>
         </select>
        </td>
    </tr>
    <tr>
        <td>Tanggal</td>
        <td>:</td>
        <td>
        <!--<select id="tanggal" name="tanggal">
            <option value="2013-04-01">01-04-2013</option>
            <option value="2013-04-02">02-04-2013</option>
            <option value="2013-04-03">03-04-2013</option>
            <option value="2013-04-04">04-04-2013</option>
            <option value="2013-04-05">05-04-2013</option>
            <option value="2013-04-06">06-04-2013</option>
         </select>-->
		 <input type="text" id="datepicker" name="tanggal" />
        </td>
    </tr>
    <tr>
        <td>Dewasa</td>
        <td>:</td>
        <td>
        <select id="dewasa" name="dewasa">
            <option value="1" selected="selected" >1</option>
            <option value="2">2</option>
            <option value="3">3</option>
			<option value="2">4</option>
			<option value="2">5</option>
			<option value="2">6</option>
			<option value="2">7</option>
         </select>
        </td>
    </tr>
    <tr>
        <td>Anak</td>
        <td>:</td>
        <td>
        <select id="anak" name="anak">
			<option selected="selected">0</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
			<option value="2">4</option>
			<option value="2">5</option>
			<option value="2">6</option>
         </select>
        </td>
    </tr>
    <tr>
        <td>Bayi</td>
        <td>:</td>
        <td>
        <select id="bayi" name="bayi">
			<option selected="selected">0</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
			<option value="2">4</option>
			<option value="2">5</option>
         </select>
        </td>
    </tr>
	
    <tr>
        <td>Proses</td>
        <td>:</td>
        <td>
        <input type="submit" id="submit" name="submit" value="Cari Sekarang...">
        </td>
    </tr>
</table>
</form>
<hr>
<div id="result">
 
</div>
</body>
</html>
Please Tell Me ..

Is The script I created this effective?
or is there another easier way?

I am having trouble in terms of design when using this script.

demo:http://jatinangor-service.com/phpdn/

I hope there is a master that can Guide me for this project.
Newbie The Passion for Learning
User avatar
techkid
Forum Commoner
Posts: 54
Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives

Re: [HELP] API KEY PHP, JSON, JQUERY

Post by techkid »

This is ok. As long as you need Ajax/Seamlessness, this it the way to go.
User avatar
Grandong
Forum Commoner
Posts: 65
Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:

Re: [HELP] API KEY PHP, JSON, JQUERY

Post by Grandong »

techkid wrote:This is ok. As long as you need Ajax/Seamlessness, this it the way to go.
Hi Thx For Your Reply..
Is there another way to process JSON API key ?
Maybe you have experience with a project like this
<?php
:D
?>
Newbie The Passion for Learning
Post Reply