I'm having a strange problem. In my app, when the user taps a button, it retrieves results taken from an online MySQL database to the given parameters.
When the selection parameter has the value Cost, it executes a slightly different SQL query (second query in the ChooseQuery Sub). Since the user can enter a range for the cost, I created a custom type named CostRange which can take two values. (from and to)
But the query under Cost only returns an empty result set. I tested it in the Server's PHPMyAdmin's SQL window and it returns correct results over there. However when I run it through the app, no results. (The user entered values get assigned to variables fc and tc, I debugged and checked)
Alternately I tried with this query too but to no avail.
The other 3 queries work just fine though.
Can anyone tell me what I'm doing wrong or missing here?
Thank you
When the selection parameter has the value Cost, it executes a slightly different SQL query (second query in the ChooseQuery Sub). Since the user can enter a range for the cost, I created a custom type named CostRange which can take two values. (from and to)
B4X:
Sub Globals
Type CostRange (FromCost As String, ToCost As String)
End Sub
Sub btnSearch_Click
Dim selection, search_string As String
Dim range As CostRange
selection = spnrSearchBy.SelectedItem.Trim
search_string = txtSearch.Text.Trim
range.FromCost = txtFrom.Text.Trim
range.ToCost = txtTo.Text.Trim
If selection = "Cost" Then
ChooseQuery(selection, Null, range.FromCost, range.ToCost)
Else
ChooseQuery(selection, search_string, Null, Null)
End If
End Sub
Sub ChooseQuery (param As String, str As String, fc As String, tc As String)
If param = "Area" Then
ExecuteRemoteQuery("SELECT T.SID, Name, Cost FROM locations L INNER JOIN service_locations SL ON L.Code = SL.Loc_Code LEFT JOIN taxi_services T ON T.SID = SL.SID WHERE Location LIKE '%" & str.Trim & "%' AND Active = 1 GROUP BY T.SID ", SEARCH_RESULTS)
Else If param = "Cost" Then
ExecuteRemoteQuery("SELECT SID, Name, Cost FROM taxi_services WHERE Cost BETWEEN '%" & fc.Trim & "%' AND '%" & tc.Trim & "%' AND Active = 1 ", SEARCH_RESULTS)
Else If param = "Service Name" Then
ExecuteRemoteQuery("SELECT SID, Name, Cost FROM taxi_services WHERE Name LIKE '%" & str.Trim & "%' AND Active = 1 ", SEARCH_RESULTS)
Else If param = "Hotline" Then
ExecuteRemoteQuery("SELECT S.SID, Name, Cost, Phone_No FROM hotlines H INNER JOIN taxi_services S ON H.SID = S.SID WHERE Phone_No LIKE '%" & str.Trim & "%' AND Active = 1 ", SEARCH_RESULTS)
End If
End Sub
But the query under Cost only returns an empty result set. I tested it in the Server's PHPMyAdmin's SQL window and it returns correct results over there. However when I run it through the app, no results. (The user entered values get assigned to variables fc and tc, I debugged and checked)
Alternately I tried with this query too but to no avail.
B4X:
ExecuteRemoteQuery("SELECT SID, Name, Cost FROM taxi_services WHERE Cost >= '%" & fc & "%' AND Cost <= '%" & tc & "%' AND Active = 1 ", SEARCH_RESULTS)
The other 3 queries work just fine though.
Can anyone tell me what I'm doing wrong or missing here?
Thank you
Last edited: