mysql 쿼리를 수행하는 스크립트가 있고 행이 있으면 메시지를 인코딩합니다. 하지만 메시지와 쿼리의 전체 결과를 인코딩해야합니다. 이 코드는 내가 사용된다JSON 인코딩 mysql 쿼리
{ "key": [ { "ID": "1", "NAME": "Test", "ADDRESS": "Test-street 123", "CONDITION": "false", "status": "ok" } ] }
그래서 내가 $ 메시지에 추가해야하는지 이것을 달성하기 :
<?php
include 'config.php';
// Connect to server and select databse.
mysql_connect("$dbhost", "$dbuser", "$dbpass")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$id = @$_POST['id'];
// To protect MySQL injection (more detail about MySQL injection)
$id = stripslashes($id);
$id = mysql_real_escape_string($id);
$sql="Select * from table1 where ID='$id'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $id and $mypassword, table row must be 1 row
if ($count == 1) {
$message = array('status' => 'ok');
}
header('Content-Type: application/json');
print '{"key":'. json_encode($message) .'}';
?>
그래서 내가 JSON 모습 싶어?
당신은 결과 아무것도하지 않는 선택된 행의 수를 검색 제외. – Gumbo