2017-06-09 7 views
0

私はBD MySQLで検索していますが、私は必要な結果を得ることができません。これは、これは角度コードIは、 "空の行を参照してコンソールに結果 '投稿クエリの結果を得るAngularjs

$http.post("search.php", value).then(function success (response) { 
      console.log(response); 
      console.log(response.data); 
     },function error (response){ 
      console.log(response.data); 
     } 
    );` 

" であるPHPコード

$mass = json_decode(file_get_contents('php://input'), true); 
foreach ($mass as $mass_item) { 
if($mass_item['name']=="Наименование" && isset($mass_item['val'])) 
$exp=$mass_item['val']; 
} 
$query = "SELECT * FROM Companies WHERE LOWER(name) RLIKE 
LOWER('".$exp."') "; 
$result = mysql_query($query) or die(); 
while($row=mysql_fetch_array($result)){ 
    echo json_encode($row); 
} 

あります。しかし、前にwhileのようにエコーを1つ追加すると、echo $row['name']のようにコンソールになります 私はjson形式でクエリを取得する必要があります。助けてください。 enter image description here

答えて

2

あなたがそのようなことにすべての行、変更のPHPコードをエコーし​​ようとしている。

$resultJson = []; 
while($row=mysql_fetch_array($result)){ 
    $resultJson[] = $row; 
} 
echo json_encode($resultJson); 
die; 
+0

グレートを!ありがとう!!! – RoGGeR

+0

@RoGGeR np、答えとしてマーク) – kRicha

+0

私はもう一度plsを助けますか?)今はjsonオブジェクトを取得しますが、プロパティは複製されます。 {0: "John"、1: "123"、名前: "John"、電話: "123"} – RoGGeR

関連する問題