2013-12-17 5 views
0

PHP를 통해 MySQL에서 단일 필드를 가져 와서 내 안드로이드 응용 프로그램에서 사용하려고합니다. 어떻게 json을 사용하지 않고 PHP에서 응답을 읽을 때 하나의 필드를 얻을 수 있습니까? 또는 나를 도울 수있는 튜토리얼이 있다면, 나는 감사 할 것이다HTTP 응답에서 단일 필드 얻기

여기

<?php 
    $host=""; // Host name 
    $user=""; // Mysql username 
    $pswd=""; // Mysql password 
    $db="pet_home"; // Database name 
    //$tbl_name="users"; // Table name 

    $conn = mysql_connect($host, $user, $pswd); 
    mysql_select_db($db, $conn); 
    $username=$_POST['username']; 
    $password=$_POST['password']; 
    $result=mysql_query("select * from users where username='$username' and  
    password='$password'")or die (mysql_error()); 
    $count=mysql_num_rows($result); 
    $row=mysql_fetch_array($result);  
      if ($count > 0){ 
      echo "\n"; 
      echo $row['filter_st']; 
      echo "\n"; 
      echo $row['heat_st']; 
      echo "\n"; 
      echo $row['led_st'];    
      }else{ 
      echo 0; 

      }  

     ?> 
+0

또한 데이터베이스 입력 삭제에 대한 자습서를 읽어야합니다. – skrilled

+0

하지만 그 값을 returno해야합니다 ... 그렇지 않다면, 그냥 그 값을 선택하고 echo $ row [ 'myvalue']; – Hackerman

+0

그게 내가 응답에서 그 값을 각각 하나씩 얻는 것을 찾고있는거야 – user1928775

답변

0

그냥 아니, 다음, 더 파서를 하나의 필드를 에코하지 내 코드

public Boolean postData(String a,String b) { 



        response = null;   

        String response = null; 

        try 
        { 
         // url = new URL("http://"+"URL"+"/new/check2.php"); 
         ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 
         postParameters.add(new BasicNameValuePair("check",x)); 
         postParameters.add(new BasicNameValuePair("username", a)); 
         postParameters.add(new BasicNameValuePair("password", b)); 

         response = CustomHttpClient.executeHttpPost("http://"+"URL"+"/new/checkedited.php",postParameters); 
        // result = response.toString(); 
        result = result.replaceAll("\\s+", ""); 



        } 
        catch(Exception e) 
        { 
         e.printStackTrace(); 
        } 
        return true; 
      } 

PHP의 JSON 아니요 ...

예 : 'heat_st'를 원할 경우 : (에코는 응답 전화이기 때문에 하나의 에코 만 사용합니다.)

echo $row['heat_st']; 

그런 다음 당신의 안드로이드 응용 프로그램에 대한 응답은 당신이 원하는 결과가 단지 하나 개의 문자열이 될 것입니다. (필요하면 쉽게 자바 예를 들어 int로 변환 할 수 있습니다) 당신이 필요로하는 경우

여러 필드, JSON 갈 방법입니다.

관련 문제