Hello everyone.
I'm having a problem while accessing a mysql database.
In this particular case, I need to access 2 tables from the same database.
I fetch the data from the first table, and it works OK. I can see it on a list view.
Then I get the data from the the type.field where I have a value which is an ID to the second table.
I need to go to the second table using this ID and fetch the value.
That's where the problem starts.
The code is similar to the one below. and all variables apear to be properly DIMed in the correct Globals or Process Globals
It maybe a little messed at the moment, as I've tryed lots of diferent things.
The problem is that I have all the data from the first table, but while looping trough it, reading the ID i need and trying to read the values from the second table,I only get the first one.
It's like if the loop isn't working, but it is, because the toastmessage in sub ler_dados_aluno shows the correct values.
Can someone help me with this ? What am I doing wrong ?
Thanks in advance.
I'm having a problem while accessing a mysql database.
In this particular case, I need to access 2 tables from the same database.
I fetch the data from the first table, and it works OK. I can see it on a list view.
Then I get the data from the the type.field where I have a value which is an ID to the second table.
I need to go to the second table using this ID and fetch the value.
That's where the problem starts.
The code is similar to the one below. and all variables apear to be properly DIMed in the correct Globals or Process Globals
It maybe a little messed at the moment, as I've tryed lots of diferent things.
The problem is that I have all the data from the first table, but while looping trough it, reading the ID i need and trying to read the values from the second table,I only get the first one.
It's like if the loop isn't working, but it is, because the toastmessage in sub ler_dados_aluno shows the correct values.
Can someone help me with this ? What am I doing wrong ?
Thanks in advance.
B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
hc.Initialize("hc")
End If
Activity.LoadLayout("1")
ler_dados_agenda
Sub ler_dados_agenda
ProgressDialogShow("Lendo_agenda")
ExecuteRemoteQuery("SELECT id_agenda,data,hora_inicio,hora_fim,id_aluno,id_instrutor,matricula,id_status FROM agenda ORDER BY id_agenda", ler_agenda)
End Sub
Sub ler_dados_aluno (aluno As String)
id=aluno
ExecuteRemoteQuery("SELECT nome,apelido FROM alunos WHERE id_aluno='" & id &"'", ler_aluno)
ToastMessageShow (id, False) - ALL ID VALUES APPEAR . NO PROBLEM HERE
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2("bla bla bla..my server and service, Query.GetBytes("UTF8"))
hc.Execute(req, TaskId)
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log("Erro: " & Reason & ", codigo: " & StatusCode)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
ProgressDialogHide
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
res = Response.GetString("UTF8")
Log("resposta do servidor: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select TaskId
Case ler_agenda
Dim agenda As List
agenda = parser.NextArray 'devolve em maps
For i = 0 To agenda.Size - 1
Dim m As Map
m = agenda.Get(i)
Dim tl As linhas_agenda
tl.campo1 = m.Get("id_agenda")
tl.campo2 = m.Get("data")
tl.campo3 = m.Get("hora_inicio")
tl.campo4 = m.Get("hora_fim")
tl.campo5 = m.Get("id_aluno")
tl.campo6 = m.Get("id_instrutor")
tl.campo7 = m.Get("matricula")
tl.campo8 = m.Get("id_status")
ler_dados_aluno (tl.campo5)
ToastMessageShow (id, False)
'ListView1.AddSingleLine(tl.campo1&" "& tl.campo2&" "&tl.campo3&" "&tl.campo4&" "&tl.campo5&" "&tl.campo6&" "&tl.campo7&" "&tl.campo8)
Next
ProgressDialogHide
Case ler_aluno
Dim alunos As List
alunos = parser.NextArray 'devolve em maps
For j = 0 To alunos.Size - 1
Dim n As Map
n = alunos.Get(j)
la.nome = n.Get("nome")
la.apelido = n.Get("apelido")
nome2=n.Get("nome")
apelido2=n.Get("apelido")
Next
End Select
Response.Release
End Sub
Last edited: