UPDATE nama_tabel SET nama_kolom = TRIM(nama_kolom) WHERE nama_kolom LIKE ' %' OR nama_kolom LIKE '% ';
inipendapat.blogspot.com
Ini pendapatku. Apa pendapatmu?
Thursday, July 13, 2023
Friday, December 9, 2022
Select Duplicate Value
SELECT
`kode`,
COUNT(`kode`)
FROM
`table_name`
GROUP BY `kode`
HAVING COUNT(`kode`) > 1
Monday, June 13, 2022
Tuesday, April 26, 2022
Wednesday, June 16, 2021
Wednesday, January 20, 2021
UPDATE TABLE 1 WHERE ID=TABLE 2
UPDATE `tb_barang_temp` AS t1
JOIN `tb_type` AS t2
ON t1.type=t2.type
SET t1.`type`=t2.id
Monday, January 11, 2021
UPDATE RESI SECARA MASAL MENGGUNAKAN API RAJAONGKIR DENGAN PHP NATIVE
Berikut cara meng update resi secara masal yang ada di database menggunakan API Rajaongkir versi pro. Di sini sy belum menjalankan querynya, hanya menampilkan dalam bentuk echo untuk mengecek apakah perintahnya dijalankan sesuai dengan keinginan kita.
Jika teman2 ingin menjalankan querynya maka tinggal ganti baris:
echo "<th>RESI ". $resi." Status awal ".$sr." telah diupdate menjadi : ".$status_pengiriman." Penerima: ".$penerima_paket." Tgl. Terima ".$tgl_terima."</th>";
menjadi :
UPDATE tabel SET status='$status_pengiriman' WHERE ................
<?php
include "koneksi.php";
function getLacak($resi,$kurir,$api) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://pro.rajaongkir.com/api/waybill",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "waybill=".$resi."&courier=".$kurir."",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded",
"key: ".$api
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$show = "cURL Error #:" . $err;
} else {
$show = $response;
}
return $show;
}
$kurir = "jnt";
$api = 'GANTI DENGAN API KE ANDA'; //Isi dengan api dari rajaongkir
$no=1;
$cek1 = mysqli_query($koneksi, "SELECT resi, status FROM tb_sales WHERE status!='Finish'");
echo "<table border='1'>";
while($dr = mysqli_fetch_array($cek1)){
$resi=substr($dr['resi'],-12);
$sr = $dr['status'];
$lacakpaket = getLacak($resi,$kurir,$api);
$data = json_decode($lacakpaket, TRUE);
if (isset($data['rajaongkir']['result'])) {
$status_paket = $data['rajaongkir']['result']['summary']['status'];
$kode_kurir = $data['rajaongkir']['result']['summary']['courier_code'];
$nama_kurir = $data['rajaongkir']['result']['summary']['courier_name'];
$no_resi = $data['rajaongkir']['result']['summary']['waybill_number'];
$service_kurir = $data['rajaongkir']['result']['summary']['service_code'];
$tgl_kirim = $data['rajaongkir']['result']['details']['waybill_date'];
$jam_kirim = $data['rajaongkir']['result']['details']['waybill_time'];
$berat_barang = $data['rajaongkir']['result']['details']['weight'];
// Detail Pengirim
$nama_pengirim = $data['rajaongkir']['result']['details']['shippper_name'];
$alamat_ori1 = $data['rajaongkir']['result']['details']['shipper_address1'];
$alamat_ori2 = $data['rajaongkir']['result']['details']['shipper_address2'];
$alamat_ori3 = $data['rajaongkir']['result']['details']['shipper_address3'];
$kota_ori = $data['rajaongkir']['result']['details']['shipper_city'];
// Alamat singkat pengirim
$asal = $data['rajaongkir']['result']['details']['origin'];
// Detail Penerima
$nama_penerima = $data['rajaongkir']['result']['details']['receiver_name'];
$alamat_dest1 = $data['rajaongkir']['result']['details']['receiver_address1'];
$alamat_dest2 = $data['rajaongkir']['result']['details']['receiver_address2'];
$alamat_dest3 = $data['rajaongkir']['result']['details']['receiver_address3'];
$kota_dest = $data['rajaongkir']['result']['details']['receiver_city'];
// Alamat singkat penerima
$tujuan = $data['rajaongkir']['result']['details']['destination'];
// Status Pengiriman
$status_pengiriman = $data['rajaongkir']['result']['delivery_status']['status'];
$penerima_paket = $data['rajaongkir']['result']['delivery_status']['pod_receiver'];
$tgl_terima = $data['rajaongkir']['result']['delivery_status']['pod_date'];
$jam_terima = $data['rajaongkir']['result']['delivery_status']['pod_time'];
}
echo "<tr>";
echo "<th>".$no++."</th>";
echo "<th>RESI ". $resi." Status awal ".$sr." telah diupdate menjadi : ".$status_pengiriman." Penerima: ".$penerima_paket." Tgl. Terima ".$tgl_terima."</th>";
echo "</tr>";
}
echo "</table>";
Mudah mudahan bermanfaat.