0% found this document useful (0 votes)
66 views3 pages

$tabel - Nya $var4: Query

This PHP code is incrementing a meter counter for a coin-based system. It first checks if a coin record already exists for the given coin ID. If so, it checks the record's date against the current date and either updates the existing record's meter count, or inserts a new record if the dates do not match. If no record exists, it inserts a new one with an initial meter count of 1. The code handles inserting new records and updating existing records appropriately based on whether the coin record date matches or differs from the current date.

Uploaded by

Andy Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views3 pages

$tabel - Nya $var4: Query

This PHP code is incrementing a meter counter for a coin-based system. It first checks if a coin record already exists for the given coin ID. If so, it checks the record's date against the current date and either updates the existing record's meter count, or inserts a new record if the dates do not match. If no record exists, it inserts a new one with an initial meter count of 1. The code handles inserting new records and updating existing records appropriately based on whether the coin record date matches or differs from the current date.

Uploaded by

Andy Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1 <?

PHP
2
3 $tabel_nya = 'coin2';
4
5 $var4 = time('d-m-Y');
6
7 // awal AREA PROGRAM UTK COIN
8
9 echo "berhasil masuk";
10 echo "<br />";
11
12 $test = "SELECT id,FA_Coin,Meter_Coin,Id_Tiket,Tgl_Jam FROM $tabel_nya WHERE
FA_Coin = '$klik'";
13
14 $hasil = mysqli_query($conn, $test);
15
16 $row=mysqli_fetch_row ($hasil);
17 $id = $row[0];
18 $fa_coin= $row[1];
19 echo $fa_coin;
20 $coin = $row[2];
21
22 if(!$fa_coin){
23 echo "tdk ditemukan xxx";
24 echo "<br />";
25 // Jika ada Coin SLOT baru langsung ditambahkan secara otomatis
26 // include ("CoinSlot_Baru.php");
27
28 $awal =1;
29
30 $data ="INSERT INTO $tabel_nya (FA_Coin, Meter_Coin) VALUES ('$klik',
'$awal')";
31
32 if ($conn->query($data) === TRUE) {//awal
33
34 echo "Record baru utk Meter_Coin berhasil ditambahkan";
35 echo "<br />";
36 }
37
38 else {
39 echo "Error: " . $data . "<br>" . $conn->error;
40 } //akhir
41
42 }
43
44 else // ADA RECORD yang sama, record sdh ada --> cek
tgl --> update record
45 {
46 echo "ditemukan xxx";
47
48
49 //awal CEK RECORD YG PALING AKHIR --> CEK TGL APAKAH SAMA
50 $result = "SELECT id,FA_Coin,Meter_Coin, Id_Tiket,Tgl_Jam FROM $tabel_nya
WHERE FA_Coin = '$klik' ORDER BY Tgl_Jam DESC limit 1";
51
52 $hasil = mysqli_query($conn, $result);
53
54 $row=mysqli_fetch_row ($hasil);
55 $id = $row[0];
56 $fa_coin= $row[1];
57 $meter_coin = $row[2];
58
59 $tgl = date_create($row[4]);
60
61
62 if (date_format($tgl, 'd') == date('d', $var4) // cek tgl
63 && date_format($tgl, 'm') == date('m', $var4) // cek bulan
64 && date_format($tgl, 'Y') == date('Y', $var4)) // cek tahun
65 {//-3
66
67 // include ("updatemeter.php");
68 echo "tanggal sama";
69
70 //awal JIKA ADA RECORD PADA TGL YANG SAMA --> PROSES
UPDATE METER
71 // $x = $row[2];
72
73 echo "<br />";
74 echo $meter_coin;
75 echo "<br />";
76
77 $meter_coin++;
78
79 echo "<br />";
80 echo $meter_coin;
81 echo "<br
/>";

82
83 $sql = " UPDATE $tabel_nya SET
Meter_Coin='$meter_coin' WHERE id=$id";
84
85 if (mysqli_query($conn, $sql))
86 {
87 echo "UPDATE Record tanggal Sama, Berhasil";
88 }
89
90 else
91
92 {
93 echo "Error updating record: " .
mysqli_error($conn);
94 }
95
96 //akhir JIKA ADA RECORD PADA TGL YANG SAMA --> PROSES
UPDATE METER
97
98 } //-3
99
100
101 elseif ( date('d', $var4) >= date_format($tgl, 'd') //cek tgl
102 || date('m', $var4) >= date_format($tgl, 'm') //cek bln
103 || date('Y', $var4) >= date_format($tgl, 'Y')) // cek thn
104 {
105
106 echo "tgl tidak sama";
107 echo "<br />";
108
109 // include ("record_tglbaru.php"); // meter dgn
record baru
110
111 // awal record baru utk tgl tdk sama
112
113 $meter_Coin++;
114
115 $data ="INSERT INTO $tabel_nya (FA_Coin, Meter_Coin)
VALUES ('$fa_coin', '$meter_coin')";
116
117 if ($conn->query($data) === TRUE) {
118 // $last_id = mysqli_insert_id($conn);
119 // echo $last_id;
120 echo "Record tgl baru berhasil ditambahkan";
121 echo "<br />";
122 }
123
124 else {
125 echo "Error: " . $data . "<br>" .
$conn->error;
126 }
127
128 //akhir, record baru utk tgl tdk sama
129
130 }
131 else
132 {
133 echo" tgl nya salah ";
134 }
135
136
137 //akhir CEK RECORD YG PALING AKHIR --> CEK TGL APAKAH SAMA
138
139
140
141
142 } // akhir AREA PROGRAM UTK Coin
143
144 ?>
145

You might also like