Android Question Get max number from mysql

Dman

Active Member
Licensed User
Longtime User
I have connected to the mysql database successfully using the demo in this topic http://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/#content

I can successfully retrieve, edit and update the existing information. I have not figured out how to get the max value from a field and insert the max value + 1 into an edittext when adding a new record.In other words, I can't figure out how to display the value in an edittext.
I am thinking the select command is similar to the one below but I am confused on exactly how to display it.

ExecuteRemoteQuery("SELECT MAX(number) as max_number FROM members", Get_Max)
 
Last edited:

sorex

Expert
Licensed User
Longtime User
did you update the jobdone part?

you'll need to add another case for the Get_Max command.

there you can read out the response from the server, add 1 to it and store it in edittext.text

something like

B4X:
Select Job.JobName
Case Get_Max
label1.text=job.getstring+1
End Select

might nee a mod to
label1.text=int(job.getstring)+1
tho
 
Last edited:
Upvote 0

Dman

Active Member
Licensed User
Longtime User
I did add another case for the Get_Max part. I inserted a messagebox to see what the value of job.getstring is and it shows [{"max_number":"6823"}] and if I take the "as max_number" out of the sql statement the value is [{"MAX(number)":"6823"}]
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
ok, you encoded it as a json collection so you'll need to parse it with an extra library.

or you can comment that encode_json line in your php and just use echo $my_sqlfieldvalue;
then you can use the code I provided a few minutes ago.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
If I comment the encode_json line in the php will that mess up all my other jobs that are working fine?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
only if all the other requests are in the same php file and you only used 1 json encode for all results.

json/xml is mainly used to exchange datasets, for just 1 record or value like in your case you can just read out the response which is less hassle
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
I only have 1 php file so I assume they are all there. Is there a way to get what I need by code?
 
Upvote 0
Top