Populate spinner from mysql db

markh2011

Member
Licensed User
Longtime User
Hi,
I need some help with populating a spinner from a remote mysql db.
The sql query is embedded in the php file and returns the data if i run it from a browser so thats working but i cant figure out the syntax to load it into the spinner from thehttpC_ResponseSuccess .:confused: any help would be brilliant.
 

markh2011

Member
Licensed User
Longtime User
Hi Erel,
I have been using the "visual basic for android june 11.pdf" as my guide and for the query in the php file is :

if($action == "getdev"){
$userID = $_GET['userid'];
$result = mysql_query("select phnum, deviceID from devices WHERE userid = '$userID'" ) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['phnum'];
echo "\r\n".$row['deviceID']."\r\n";

I have tried to adapt the following syntax that populates a list view successfully.
B4X:
   lvoutput.Clear
   lvoutput.FastScrollEnabled = True
   Dim result As String
   result = Response.GetString("UTF8")
   Dim Endstring As Int
   Endstring = result.IndexOf("<!")
   result = result.SubString2(0, Endstring)
   result = result.Replace("_"," ")
   File.WriteString(File.DirInternalCache, "nettalk.txt",result)
   reader.Initialize(File.OpenInput(File.DirInternalCache, "nettalk.txt"))
   Dim ID As String
   ID = reader.ReadLine
   Do While ID <> Null
   Dim lat As String
   lat = reader.ReadLine
   Dim lon As String
   lon = reader.ReadLine
   Dim timestamp As String
   timestamp = reader.ReadLine
   lvoutput.SingleLineLayout.Label.TextSize = 10
   lvoutput.SingleLineLayout.ItemHeight = 35
   lvoutput.SingleLineLayout.Label.TextColor = Colors.Black
   lvoutput.AddSingleLine(ID &": "& lat & "  "& lon &"  " & timestamp)
   ID = reader.ReadLine
   Loop
   reader.Close
   ProgressDialogHide
   lvoutput.SetSelection(0)

my response success code which is wrong is because it does not work: 
Dim result As String
   result = Response.GetString("UTF8")
   File.WriteString(File.DirInternalCache, "spin.txt",result)
   reader.Initialize(File.OpenInput(File.DirInternalCache, "spin.txt"))
   Dim phnum As String
   phnum = reader.ReadLine
   Do While phnum <> Null
   Dim udeviceID As String
   udeviceID = reader.ReadLine
   spnDevice.AddSingleLine(phnum & "  "& udeviceID)
   spnDevice = reader.ReadLine
   Loop
   reader.Close
   ProgressDialogHide
   spnDevice.SetSelection(0)
Is it possible to use the dbutils code module with remote databases because i have used it with local sqlite dbases that are stored within the files?
This is my first attempt to use a mysql database located on a remote web server with the actual querires embedded in a phpfile.
 
Upvote 0
Top