mostrar valor de unas moneda con api
Publicado por yoclens (20 intervenciones) el 10/03/2023 02:59:52
saludos, me puse de curioso y hay algo que me llamo la atención como lo son las api y por eso quise tratar de implementarla en practica, pero no logro que se me de siempre me muestra error 500 anexo link de la documentación de la api en ella quiero tratar de mostrar el precio del petro tanto PTR como BS. Gracias de ante mano.
https://www.petro.gob.ve/es/desarrollo/
conversor
consultar registros
https://www.petro.gob.ve/es/desarrollo/
conversor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!-- conversor -->
<?php
$ch = curl_init();
$array = [
'coins' => 'PTR',
'fiats' => 'BS'
];
$data = http_build_query($array);
curl_setopt($ch, CURLOPT_URL, 'https://petroapp-price.petro.gob.ve/price/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_error($ch)) echo curl_error($ch);
else $decoded = json_decode($response, true);
foreach ($decoded as $index => $value) {
echo "$index: $value <br>";
}
curl_close($ch);
?>
<!-- fin conversor -->
consultar registros
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!-- consultar registros -->
<div class="container">
<div class="row">
<div class="card cyan darken-3">
<div class="card-tabs">
<ul class="tabs tabs-fixed-width tabs-transparent">
<li class="tab"><a class="active">Precio del Petro</a></li>
</ul>
</div>
<div class="card-content white">
<div id="test1" class="center-align light">
<table>
<thead>
<tr>
<th>PRT</th>
<th>BS.DIGITAL</th>
</tr>
</thead>
<tbody id='tabla'>
<tr>
<td><?php echo $coins; ?></td>
<td><?php echo $fiats; ?></td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- consultar registros -->
<div class="container">
<div class="row">
<div class="card cyan darken-3">
<div class="card-tabs">
<ul class="tabs tabs-fixed-width tabs-transparent">
<li class="tab"><a class="active">Listado General</a></li>
</ul>
</div>
<div class="card-content white">
<div id="test1" class="center-align light">
<table>
<thead>
<tr>
<th>TIPO DE DOCUMENTO</th>
<th>MONTO BS.DIGITAL</th>
<th>VALOR PTR</th>
<th>MONTO A CANCELAR BS.DIGITAL</th>
</tr>
</thead>
<?php
$consulta = $DB_con->query("SELECT * FROM conversor_petro_bsd ORDER BY id_documento;");
if($consulta->rowCount() > 0){
$i=1;
?>
<?php
while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {
?>
<tbody id='tabla'>
<tr>
<td><?php echo $linea['documento']; ?></td>
<td><?php echo $PTR; ?> BSD</td>
<td><?php echo $linea['monto_petro']; ?> PTR</td>
<td><?php echo $BS; ?> BSD</td>
<td>
</td>
</tr>
</tbody>
<?php
$i++;
}
}
else
echo "<div class='col s12 card-panel yellow darken-2 center'>
<h5 class='black-text text-darken-2 center CONDENSED LIGHT5'>
¡ Advertencia: No se ha encontrado ningún registro !
</h5>
</div>";
echo "</table>";
?>
</div>
</div>
<!-- fin consultar registros -->
Valora esta pregunta


0