I'm working with OkHttpUtils2 and JSON on a mysql project. The application connects well to the XAMPP server. I'm working with Xampp and php 7 and mysqli. The main problem is that even though it inserts data to a table through a php file it can't read a "SELECT SUM" I mean... I need to fill a label and give the sum of a whole column but I still can not bring the sum. the query in the php file works but in B4A I still can not bring that value inside the label. Maybe it's because I still don't understand JobDone well. I've done it in a thousand ways. I've watched the Erel video where he teaches how to bring data from a Json and I've adapted it to my project and it doesn't work. If someone knows the way and helps me I thank them in advance. Thank you
This is my mysql query into operaciones.php
there are many "case" but I can't get this one going.
what i have in Activity Module
If it is necessary to remake the code there are no problems. I just want to bring that value from the mysql table to my label in the PAGOS (PAYMENTS) Activity Module. I have tested the php file with "POSTMAN" to see if the query into the php file brings this value and actually pulls it. I think I have the problem in B4A
This is my mysql query into operaciones.php
PHP:
case "sumarcash":
$sql = "SELECT SUM(monto) AS TotalesC FROM gastoscash";
$resultado = $mysqli->query($sql);
$fila=$resultado->fetch_assoc();
$TotalCash=$fila['TotalesC'];
print json_encode($TotalCash);
break;
there are many "case" but I can't get this one going.
what i have in Activity Module
B4X:
Public Sub Initialize (labelTemp As Label)
labelLocal=labelTemp
End Sub
Public Sub downloadInfo '< I call this one on Activity Create
Log("class:downloadinfo")
ProgressDialogShow("Obteniendo Suma..")
remoteQuery("SELECT SUM(monto) AS TotalesF FROM gastoscash", "sumcash")
End Sub
Private Sub remoteQuery(query As String, nombreJob As String)
Log("class:remoteQuery")
Dim job As HttpJob
job.Initialize(nombreJob,Me )
job.PostString("http://localhost:8080/gastosxampp/operaciones.php", query)
End Sub
Sub JobDone(Job As HttpJob)
Log("class:JobDone("&Job.GetString&")")
ProgressDialogHide
If Job.Success Then
Dim res As String
res=Job.GetString
Log("Server response: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case "sumarcash"
Dim l As List
l= parser.NextArray
If l.Size = 0 Then
lblTotaC.Text="SIN DATOS"
Else
Dim m As Map
m= l.Get(0)
lblTotaC.Text= m.Get("TotalesC")
End If
End Select
Else
ToastMessageShow("Error: " & Job.ErrorMessage,True)
End If
Job.Release
End Sub
If it is necessary to remake the code there are no problems. I just want to bring that value from the mysql table to my label in the PAGOS (PAYMENTS) Activity Module. I have tested the php file with "POSTMAN" to see if the query into the php file brings this value and actually pulls it. I think I have the problem in B4A