PHP combined with Android client to implement query interactive instance _php tutorial

Source: Internet
Author: User
Tags php server

PHP combined with Android client to implement query interactive instance


This article to you to share is PHP with the Android client implementation of the query interactive instance, the Java side of the main three steps to achieve: the first HTTP request. Network request-related operations, the second step, using the Execute method to send an HTTP GET request, and return the HttpResponse object, the third step, use the GetEntity method to live to return the result. Small partners with the necessary reference

PHP Server side:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

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, $pcallid);

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 prevent the appearance of []

$jsonstr = Json_encode ($getdata->result_array (), json_force_object);

Echo $jsonstr;

}

}

Java android:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

Doasktask = new Runnable () {

@Override

public void Run () {

Todo

HTTP request is made here. Network requests related operations

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);

The second step is to use the Execute method to send an HTTP GET request and return the HttpResponse object

HttpResponse HttpResponse = null;

try {

HttpResponse = new Defaulthttpclient (). Execute (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) {

The third step is to 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 mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/994738.html www.bkjia.com true http://www.bkjia.com/PHPjc/994738.html techarticle PHP combined with the Android client to implement the query interactive instance this article is to share the PHP with the Android client implementation of the query interactive instance, the Java side of the main three steps to achieve: first of all, HTTP R ...

  • 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.