Pravee7094
Active Member
Hello all,
I try to list the data from the postgres database using B4x Table. But I got some Errors.
But when I list the same data using listview Its perfectly works. What else I miss? I attached the Two type of codes.
List data using B4X Table : (Not Working)
PHP code:
Here, List data using ListView: (working)
PHP code same php code)
Any body help? Or any other code snippets are there?
Thanks
Praveen
I try to list the data from the postgres database using B4x Table. But I got some Errors.
But when I list the same data using listview Its perfectly works. What else I miss? I attached the Two type of codes.
List data using B4X Table : (Not Working)
B4X:
Sub PrintTable
printDataTable.AddColumn("Name", printDataTable.COLUMN_TYPE_TEXT)
printDataTable.AddColumn("Email", printDataTable.COLUMN_TYPE_TEXT)
printDataTable.AddColumn("City", printDataTable.COLUMN_TYPE_TEXT)
printDataTable.AddColumn("Distirct", printDataTable.COLUMN_TYPE_TEXT)
Dim Connect As HttpJob
Connect.Initialize("PrintData", Me)
Connect.Download(Main.strURL & "print_data.php")
End Sub
Sub JobDone (Job As HttpJob)
ProgressDialogHide
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "PrintData"
Dim res As String
res = Job.GetString
Log(res)
Dim parser As JSONParser
parser.Initialize(res)
Dim ListAllItems As List
ListAllItems.Initialize
ListAllItems = parser.NextArray 'returns a list with maps
For i = 0 To ListAllItems.Size - 1
Dim Person As Map
Person = ListAllItems.Get(i)
Log(Person)
Dim row() As Object
row(0) = Person.Get("name")
row(1) = Person.Get("email")
row(2) = Person.Get("city")
row(3) = Person.Get("distirct")
ListAllItems.Add(row)
Next
printDataTable.SetData(ListAllItems)
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
PHP code:
PHP:
<?php
$dbconn = pg_connect("host=localhost port=5433 dbname=dbname user=postgres password=password");
$q = pg_query("SELECT name,email,city,distirct FROM product_item ORDER BY name ASC");
$rows = array();
while($r = pg_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
?>
Here, List data using ListView: (working)
B4X:
Sub ListTable
Dim Connect As HttpJob
Connect.Initialize("PrintData", Me)
Connect.Download(Main.strURL & "print_data.php")
End Sub
Sub JobDone (Job As HttpJob)
ProgressDialogHide
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "PrintData"
Dim res As String
res = Job.GetString
Log(res)
Dim parser As JSONParser
parser.Initialize(res)
Dim ListAllItems As List
ListAllItems.Initialize
Dim personName As String
ListAllItems = parser.NextArray 'returns a list with maps
For i = 0 To ListAllItems.Size - 1
Dim person As Map
person = ListAllItems.Get(i)
Log(person)
personName = person.Get("name")
lstViewItems.AddSingleLine(personName)
Next
PHP code same php code)
PHP:
<?php
$dbconn = pg_connect("host=localhost port=5433 dbname=dbname user=postgres password=password");
$q = pg_query("SELECT name,email,city,distirct FROM product_item ORDER BY name ASC");
$rows = array();
while($r = pg_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
?>
Any body help? Or any other code snippets are there?
Thanks
Praveen