B4J Question jokhttputils2 stringhandling

ThRuST

Well-Known Member
Licensed User
Longtime User


Hello, I am learning the jokhttputils2 library in B4J and have managed to request queries from a mySQL database located on a server. It's easy to read one cell, however when I read all data in i.e Firstname, I've noticed that all names is sent as a long string in job1.GetString so that when put in a TableView all items is treated as one long string even if I add print $row["Firstname"] . chr(13);
Will I have to split the string job1.GetString with regex in JobDone sub or is JSON the solution?
This problem make it impossible to click on a single line in TableView since all added items is treated as one long string. Please help me!!

Only relevant parts from code is shown

B4J
B4X:
job1.Initialize("Job1", Me)
job1.Download("http://www.mydomain.com/test.php")

PHP:
$sql = "SELECT Firstname FROM Contacts";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
        print $row["Firstname"] . chr(13);
    }
} else {
    echo "0 results";
}
$conn->close();

B4J
B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
         'Log(Job.GetString)
        TableView1.SetColumns(Array As String("Column 1", "Column 2", "Column 3"))
         Row(0) = "a"
         Row(1) = "b"
         Row(2) = "c"

        Row(0) = job1.GetString
        TableView1.Items.Add(Row)

 
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
Thanks, but when I tried this in JobDone the singleselection does not correspond to the line I am selecting. I can select from index 1 and halfway then when I scroll down to select one of the lower items in the Tableview it selects another row. I followed your advice and also added code to make the items visible in the tableview, since that's what I want to achieve, to read from my MySQL database and have the jokhttputils2 use Job.GetString from the database. I'm sorry if I missunderstood which library handles what, but I'm new to this. I added jokhttputils2 to access httpjob, so that's what I am starting out with. If I can learn to do this without JSON I am happy because I think JSON seems complex to use. Your solution looks great as a shortcut, but how to list the items properly inthe tableview? I attach an image for what happens.

B4X:
For Each Item As String In Regex.Split(Chr(13), Job.GetString)
         'Log(Item)
        Row(0) = Item.Trim
        Tableview1.Items.Add(Row)
        Next

Blue arrow is what I clicked at.


Note: It does show correctly in log(item) as you wrote.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Erel, it seems to work with a ListView, I just tried it and selection works ok. Can you please tell me why I could not add the items into the TableView, because that's really the control that I want to use. Perhaps ListView can have columns (as it is possible in .NET C sharp) but this is B4J so it might be different. There must be a way to add those items to TableView instead of using JSON, so I leave this question open. Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…