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
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Wed Jul 09, 2014 12:10 pm
Sorry For bad Title
Please, Someone Help Me About:
How to GET Array to Url ?
i have form like :
Code: Select all
<?php $n=$json_results['departures']['count_adult']; ?>
<?php for($i=1;$i<=$n;$i++): { ?>
<select class="form-control" name="titlea<?= $i; ?>">
<?php foreach($json_results['required']['titlea'.$i]['resource'] as $result): ?>
<option id="<?= $result["id"]; ?>" name="<?= $result["name"]; ?>"><?= $result["name"]; ?></option>
<?php endforeach; ?>
</select>
<?php } ?>
<?php endfor; ?>
How To GET
and
To URL ?
This My Post.php
Code: Select all
<?php
$Token = $_POST['token'];
$Id = $_POST['flight_id'];
$Title = $_POST['conSalutation'];
$Cfname = $_POST['conFirstName'];
$Clname = $_POST['conFirstName'];
$Cphone = $_POST['conPhone'];
$Cmail = $_POST['conEmailAddress'];
$Adut = $_POST['adult'];
$url = "https://api.master18.tiket.com/order/add/flight?token=".$Token."&flight_id=".$Id."&child=&adult=".$Adut."&infant=&conSalutation=".$Title."&conFirstName=".$Cfname."&conLastName=".$Clname."&conPhone=".$Cphone."&firstnamea1=&lastnamea1=&ida1=&titlea1=Tuan&birthdatea1=&output=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result=curl_exec($ch);
$json_results = json_decode($result, true);
print_r($json_results);
?>
Newbie The Passion for Learning
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Wed Jul 09, 2014 12:27 pm
For openers, your <option> is going to need a value attribute. The name attribute is set in the select. Beyond that, what is it you're trying to do?
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Wed Jul 09, 2014 12:56 pm
i try to get
and post to
Code: Select all
$url = "https://api.master18.tiket.com/order/add/flight?token=".$Token."&flight_id=".$Id."&child=&adult=".$Adut."&infant=&conSalutation=".$Title."&conFirstName=".$Cfname."&conLastName=".$Clname."&conPhone=".$Cphone."&firstnamea1=&lastnamea1=&ida1=&titlea1=Tuan&birthdatea1=&output=json";
Thx Celauran, i will try
Newbie The Passion for Learning
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Wed Jul 09, 2014 2:33 pm
I Can't Solved This Problem..
Please Help Me
Newbie The Passion for Learning
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Jul 09, 2014 4:03 pm
[syntax]<option id="<?= $result["id"]; ?>" name="<?= $result["name"]; ?>"><?= $result["name"]; ?></option>[/syntax]
You do not have any values for these select options? It won't send anything when the form is posted.
(#10850)
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Thu Jul 10, 2014 1:46 pm
Problem Solved
Thx Christopher ..
but i have new problem
i have array like:
Code: Select all
Array
(
[diagnostic] => Array
(
[status] => 200
[elapsetime] => 0.0624
[memoryusage] => 6.28MB
[unix_timestamp] => 1405017825
[confirm] => success
[lang] => id
[currency] => IDR
)
[output_type] => array
[myorder] => Array
(
[order_id] => 5660330
[data] => Array
(
[0] => Array
(
[expire] => 0
[uri] =>
[order_detail_id] => 512983
[order_type] => flight
[customer_price] => 562700.00
[order_name] => CGK (Jakarta) - DPS (Denpasar, Bali)
[order_name_detail] => Sriwijaya (SJ-272 - Depart)
[order_detail_status] => recheck
[detail] => Array
(
[order_detail_id] => 512983
[airlines_name] => Sriwijaya
[flight_number] => SJ-272
[price_adult] => 562700.00
[price_child] => 0.00
[price_infant] => 0.00
[flight_date] => 12 Jul 2014
[departure_time] => 05:45
[arrival_time] => 08:35
[baggage_fee] => 0
[departure_airport_name] => SOEKARNO - HATTA
[arrival_airport_name] => Bandara Denpasar
[passengers] => Array
(
[adult] => Array
(
[0] => Array
(
[order_passenger_id] => 24020
[order_detail_id] => 512983
[type] => adult
[first_name] => David
[last_name] => Kurniawan
[title] => Tuan
[id_number] => 79787947535
[birth_date] =>
[adult_index] =>
[passport_no] =>
[passport_expiry] =>
[passport_issuing_country] =>
[passport_nationality] =>
[check_in_baggage] =>
[check_in_baggage_size] => 20
[passport_issued_date] =>
[birth_country] =>
[ticket_number] =>
)
)
)
[price] => 562700
[breakdown_price] => Array
(
[0] => Array
(
[category] => price adult
[type] => none
[value] => 562700
[currency] => IDR
[text] => Harga Dewasa
)
[1] => Array
(
[category] => total base price
[type] => price
[value] => 562700
[currency] => IDR
[text] => Harga Total
)
[2] => Array
(
[category] => baggage fee
[type] => add
[value] => 0
[currency] => IDR
[text] => Biaya Bagasi
)
[3] => Array
(
[category] => subsidy
[type] => subtract
[value] => 0
[currency] => IDR
[text] => Subsidi
)
)
)
[order_photo] => https://api.master18.tiket.com/images/icon_sriwijaya.jpg
[order_icon] => h3b
[tax_and_charge] => 14942.00
[subtotal_and_charge] => 577642.00
[delete_uri] => https://api.master18.tiket.com/order/delete_order?order_detail_id=512983
)
)
[total] => 577642
[total_tax] => 14942
[total_without_tax] => 562700
[count_installment] => 0
[promo] => Array
(
)
[discount] => Dapatkan potongan hingga IDR 14.942,00 saat anda checkout . Tidak berlaku untuk Kartu Kredit.
[discount_amount] => 14942.00
)
[checkout] => https://api.master18.tiket.com/order/checkout/5660330/IDR
[login_status] => false
[token] => ed78d6b5e4ce52c2ab374e03653cf0459de0aa60
)
and My PHP Code :
Code: Select all
<?php $n=count($json_results['myorder']['data']); ?>
<?php for($i=0;$i<=$n;$i++): { ?>
Order ID: <?= $json_results['myorder']['data'][$i]['order_detail_id']; ?>
<?php } ?>
<?php endfor; ?>
Order ID Working and display in my page, buat i get loop the Order ID an Get error Message: Undefined offset: 1
why ?
please Help Me
Newbie The Passion for Learning
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Jul 10, 2014 10:19 pm
count() returns the number of elements in an array, not the max element. There is one element in your array, so you are looping from 0..1.
(#10850)
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Fri Jul 11, 2014 8:03 am
Problem Solve
New Problem Again
IF ELSEIF
Code: Select all
$n=count($_POST['titlea']);
for($i=0;$i<$n;$i++) {
$url = "https://api.master18.tiket.com/order/add/flight?token=".$Token."&flight_id=".$Id."&child=".$Child."&adult=".$Adut."&infant=".$Infant."&conSalutation=".$Title."&conFirstName=".$Cfname."&conLastName=".$Clname."&conPhone=".$Cphone."&output=json";
$url.='&titlea'.($i+1).'='.$_POST['titlea'][$i];
$url.='&firstnamea'.($i+1).'='.$_POST['firstnamea'][$i];
$url.='&lastnamea'.($i+1).'='.$_POST['lastnamea'][$i];
$url.='&ida'.($i+1).'='.$_POST['ida'][$i];
// Birth Date
if (empty($_POST['birthdatea'][$i])) {
}
else if(empty($_POST['birthdatea'][$i])) {
$url.='&birthdatea'.($i+1).'='.$_POST['birthdatea'][$i];
};
// KTP
if (empty($_POST['passportnationalitya'][$i])) {
}
else if(empty($_POST['passportnationalitya'][$i])) {
$url.='&passportnationalitya'.($i+1).'='.$_POST['passportnationalitya'][$i];
};
// Bagasi
if (empty($_POST['dcheckinbaggagea1'][$i])) {
}
else if(empty($_POST['dcheckinbaggagea1'][$i])) {
$url.='&dcheckinbaggagea1'.($i+1).'='.$_POST['dcheckinbaggagea1'][$i];
};
}
IF ELSEIF Statement don't work, why ?
Newbie The Passion for Learning
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jul 11, 2014 8:49 am
Code: Select all
if (empty($_POST['birthdatea'][$i])) {
}
else if(empty($_POST['birthdatea'][$i])) {
$url.='&birthdatea'.($i+1).'='.$_POST['birthdatea'][$i];
};
You're testing the exact same condition. If it fails the first time, it will also fail the second.