Php and Android client to query interactive instances, php Android client instance _ PHP Tutorial

Source: Internet
Author: User
Php can use the Android client to query interactive instances and php Android client instances. Php with Android client to achieve query interaction instance, php Android client instance PHP Server: functiongetids () {$ this-output-set_header (Content-Type: applicationjson; charset php with Android client to achieve query interaction instance, php Android client instance

PHP server:

Function getids () {$ this-> output-> set_header ('content-Type: application/json; charset = utf-8 '); $ jsonstr = ''; $ pname = $ pcallid = $ pworkid = ''; if (isset ($ _ GET ['name']) {$ pname = $ _ GET ['name'];} if (isset ($ _ GET ['callid']) {$ pcallid = $ _ GET ['callid'];} if (isset ($ _ GET ['workid']) {$ pworkid = $ _ GET ['workid'];} $ this-> load-> model ('wireid _ Model'); $ this-> wireid_model-> insertonly ($ pname, $ pcall Id); if ($ pname = ''& $ pcallid ='' & $ pworkid = '') {die ();} else {$ sqlstr = 'select * from twireid where 1 = 1'; if ($ pname! = '') {$ Sqlstr = $ sqlstr." and GNAME = '{$ pname}' ";} else if ($ pcallid! = '') {$ Sqlstr = $ sqlstr." and GOLDCALLID = '{$ pcallid}' ";} else if ($ pworkid! = '') {$ Sqlstr = $ sqlstr. "and GCARDID = '{$ pworkid}'" ;}$ getdata = $ this-> wireid_model-> getsql ($ sqlstr ); // JSON_FORCE_OBJECT prevents [] $ jsonstr = json_encode ($ getdata-> result_array (), JSON_FORCE_OBJECT); echo $ jsonstr ;}}

Java Android:

DoAskTask = new Runnable () {@ Override public void run () {// TODO // http request is made here. network request related operation ggname = etname. getText (). toString (); ggworkid = etworkid. getText (). toString (); ggcallid = etcallid. getText (). toString (); String baseurl = ConfidDatas. askbaseurl; String askstr = "name =" + ggname + "& callid =" + ggcallid + "& workid =" + ggworkid; String result = null; httpGet httpGet = new HttpGet (baseurl + askstr); // Step 2, use the execute method to send an http get request and return the HttpResponse object HttpResponse httpResponse = null; try {httpResponse = new defaulthttpclient(cmd.exe cute (httpGet);} catch (ClientProtocolException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch block e. printStackTrace ();} Message msg = new Message (); Bundle data = new Bundle (); if (httpResponse. getStatusLine (). getStatusCode () = 200) {// Step 3, use the getEntity method to return the result. try {result = EntityUtils. toString (httpResponse. getEntity (); data. putString ("value", result); data. putString ("result", "isok"); msg. setData (data); handler. sendMessage (msg);} catch (ParseException e) {// e. printStackTrace ();} catch (IOException e) {// e. printStackTrace () ;}} else {// error data. putString ("value", ""); data. putString ("result", "iserr"); msg. setData (data); handler. sendMessage (msg );}}};

The above is all the content of this article. I hope you will like it.

Response PHP Server: function getids () {$ this-output-set_header ('content-Type: application/json; charset =...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.