json 데이타 사용하기
refer to : https://www.w3schools.com/js/js_json_php.asp
JSON type 을 이용해서 data 송수신하려 함.
PHP에서 제공하는 함수 json_encode/json_decode 사용
아래는 Database를 이용한 예제로 fetch후 data를 json_encode() 하여 화면에 뿌린것이다.
getSomeTopics(); echo "{\"Table\":". json_encode($topics)."}"; ?>TopicData.php
public function getSomeTopics() { $query = $this->connection->prepare("SELECT help_topic_id, name FROM TMP_help order by help_topic_id desc limit 10 "); $query->execute(); //return $query; return $query->fetchAll(\PDO::FETCH_ASSOC); }
'프로그래밍 > PHP' 카테고리의 다른 글
fileupload 에러메시지 설명 (0) | 2018.04.14 |
---|---|
angularJS 사용하기 (0) | 2018.04.01 |
Cookie 사용하기 (0) | 2018.03.18 |
Session 사용하기 (0) | 2018.03.17 |
반응형 웹개발 admin 페이지 step1 (0) | 2018.03.04 |