0
送我怎麼能倒導致分貝陣列和使用JSON發送?我怎麼能倒在陣列結果DB和使用JSON
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll();
?>
送我怎麼能倒導致分貝陣列和使用JSON發送?我怎麼能倒在陣列結果DB和使用JSON
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll();
?>
你可以使用json_encode
函數轉換成json。
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); /* it will give you array of result */
$jsonResult = json_encode($results) ; /* it will convert into json format */
echo $jsonResult ; /* this will show in ajax success calling */
?>
更多json_encode
你可以閱讀手冊json_encode
要結果轉換爲JSON – gaurav
是的,我想發送的結果,讓JS和打印這樣的: – Toprex
$。每個(單,功能(I ,數據){ $ orders.append('