Android Question Grid for remote MySQL query

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am testing the SD_SQL library to perform queries to a remote MySQL database by direct connection to it.

I need a grid (or another component, class or view) to present the records, which grid do you advise me?
I was testing with “flexible table” but it seems to work only for sqlite.

Thank you very much.
 

vecino

Well-Known Member
Licensed User
Longtime User
You mean of showing it as a typical html table?
The truth is that I have never done anything like that.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
You mean of showing it as a typical html table?
The truth is that I have never done anything like that.
B4X:
dim strHTML as stringBuilder
dim rs as ResultSet


strHTML.append("<html>")
strHTML.append("<body>")

Do While rs.NextRow
     strHTML.append("<tr>")
    strHTML.append("<td>")
     strHTML.append(rs("ClientID"))
     strHTML.append("</td>")
   
     strHTML.append("<td>")
     strHTML.append(rs("ClientName"))
     strHTML.append("</td>")
   
     strHTML.append("<td>")
     strHTML.append(rs("Age"))
     strHTML.append("</td>")
   
     strHTML.append("</tr>")
Loop

rs.close
strHTML.append("</body>")
strHTML.append("</html>")

wvMyData.LoadHTML(strHTML.tostring)
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
That's great, thank you very much.
Is it possible to detect when the user presses a row to do something? e.g. show a menu to delete the record, show some information, etc.
Should I use javascript? can it be added to the code?
 
Upvote 0

Mariano Ismael Castro

Active Member
Licensed User
That's great, thank you very much.
Is it possible to detect when the user presses a row to do something? e.g. show a menu to delete the record, show some information, etc.
Should I use javascript? can it be added to the code?
Maybe something like this
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
That's great, thank you very much.
Is it possible to detect when the user presses a row to do something? e.g. show a menu to delete the record, show some information, etc.
Should I use javascript? can it be added to the code?
yes,
B4X:
'how to make it clickable
'add a hyperlink in each row like this where 0 is a column number and i is a row number


    html = html & "<td valign='top'><a  href='http://0." & i & ".com'>"  &    ClientID & "</a></td>"
            html = html & "<td valign='top'><a  href='http://1." & i & ".com'>"  &    ClientName & "<br/>"  &  Address & "<br/>" & City & ", " & State & " " & Zip & "</a></td>"
            html = html & "<td valign='top'><a  href='http://2." & i & ".com'>"  &    Insurance & "</a></td>"
            html = html & "</tr>"
            
            'put a row data into array
            Dim values(Cursor1.ColumnCount) As String
            
            For col = 0 To Cursor1.ColumnCount - 1
                values(col) = Cursor1.GetString2(col)
                
                'Log(Cursor1.GetColumnName(col) & " " & col & "=" & Cursor1.GetString2(col))
                
            Next
            
            'Put an array into a list
            CustList.Add(values)
            


'How to catch pressed string'
Sub wvClientsList_OverrideUrl (Url As String) As Boolean

    
    Try
        
        
        
        Dim PAID As Int,Restrictions As String',Caller As String
        Dim XUI As XUI
        
    
        'parse the row And column numbers from the Url
        Private values() As String
        values = Regex.Split("[.]", Url.SubString(7))
        Private  row As Int
                    
        row = values(1)
    
        Private val(values.length) As String
        
        Private Apartment As String,Address As String
        
    'now read a row from the list
        val = CustList.Get(row)
        

        
        Main.SelectedClientID=val(0)
        
        'Alex 08/05/2024
        Main.MatchupID=val(8)
        PAID=modFun.GetPA(SQL1)
        
        If modFun.MsgStr<>"" Then
            XUI.MsgboxAsync(modFun.MsgStr,"HCMS")
            Return True
        End If
        
        Apartment=val(11)

        
    
        If Apartment<>"" Then
            Address=val(4) & " " & Apartment & CRLF &  val(5) & "," & " "  & val(6) & ", " & val(7)
        Else
            Address=val(4) & CRLF &  val(5) & "," & " "  & val(6) & ", " & val(7)
        End If
        
        
        Main.SelectedClientName=val(3)
        Main.SelectedClientAddress=Address
        
        Restrictions=modFun.GetRestriction(SQL1,PAID)
        
        Main.Restrictions=Restrictions
        Main.SelectedDistance=val(12)
        Main.Latitude=val(13)
        Main.Longitude=val(14)
        'Alex 08/05/2024
        Main.Plan=val(29)
        Main.Diagnosis=val(28)
        
        'Alex 07/31/2024
        'Akex 08/05/2024
        Main.MatchupStatus=val(30)
        
        If val(24)=0 Then
            Main.VitalsMonitored=False
        Else
            Main.VitalsMonitored=True
        End If
        
        'Alex 01/30/2023-1
        Main.Representative=val(31)
        'Alex 07/31/2024
        'Akex 08/05/2024
        Main.RepresentativePhone=val(32)
        Main.PayeeID=modFun.GetPayeeID(SQL1,PAID)
        
        Main.SelectedScheduleMonitoring=modFun.GetScheduleMonitoring(SQL1)
        
        If Main.IsPatient=False Then
        StartActivity(    DashBoard)
        Else
        StartActivity(    PatientDetails)
        End If
        
        Return True 'Don't try to navigate to this URL
    
    Catch
        Log("wvClientsList_OverrideUrl " & LastException.Message)
        modFun.ShowError("ClientsList_wvClientsList_OverrideUrl " & LastException.Message)
        Return False
    End Try
    
End Sub
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
That's great, thank you very much.
Is it possible to detect when the user presses a row to do something? e.g. show a menu to delete the record, show some information, etc.
Should I use javascript? can it be added to the code?
yes, add it into your html
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Check my example

 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Very, very interesting.
Thank you very much.
The problem is that I can't install anything on the hosting.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
It is bad practice to directly access a remote database from a mobile or web application.

Use REST APIs and if it is a hosting it must have node or apache preinstalled and languages like PHP, Javascripts, Python, etc.

You can create the APIs with php or with some existing framework.

ex.
Node and Express

Apache and Slim or (Laravel, Symfony, Lumen, etc)
Building RESTful APIs with PHP: A Practical Approach

Apache and PHP

Use Grid
B4XTable - Load data from Json (Rest API)

You can modify this example with a call to REST APIs

Note:
You can use these REST APIs in your future projects where you cannot install jRDC
.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thank you very much, friends.
I have asked if I can install jrdc, php scripts, etc. and they won't let me do it.
The only alternative they have given me is direct connection, so I can't do anything else.
Thanks again for so much useful information, it will serve me for sure for future projects.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
You can setup your own jRDC2 server and access their database
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I find it very strange since it is a hosting.

But to avoid having that restriction that I have had, I accessed it from another proprietary hosting where I placed the REST-APIs with access to the remote database of the other hosting.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…