반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- Lesson3
- 1463번
- database연결
- QA엔지니어
- 엔테크서비스
- 백준알고리즘
- BC렌트
- Lesson2
- FIDO 환불
- 벤쿠버집구하기
- 외래키설정
- 벤쿠버 렌트
- 파이도 환불
- 언마운트
- Java
- 설탕문제
- binaray_gap
- FLEX5
- FK 설정
- 프로그래머스
- 캐나다워홀
- codility
- Linux
- 부산입국
- 데이터의 무결성
- 자바
- 레노보노트북
- 벤쿠버렌트
- IntelliJ
- 리눅스
Archives
- Today
- Total
대충이라도 하자
fetch the total data in the easier way 본문
반응형
Situation :
1. fetch the data of tags
2. In data of tags, there are many columns
3. Gonna insert the data as a table type, and bring it as json type
Ex)
"tags": {
"columns": [
"url",
"adtype",
"sitecode",
"category",
"type",
"channel",
"product",
"phase",
"campaign",
"media",
"creative",
"segment"
],
"rows": [
[
"www.samsung.com/sec",
"display",
"sec",
"paid",
"display",
"facebook",
"feed",
"launch",
"sec.bespoke.2021",
"image",
"i20210101",
"re-1234"
],
[
"www.samsung.com/sec",
"display",
"sec",
"paid",
"display",
"youtube",
"trueview",
"ecommerce",
"sec.bespoke.2021",
"video",
"v20210101",
"re-1234"
],
Original Code
$tags = array_map(function ($tag) {
//imo. except channel and campaign
//everything seems not neccessary
return [
'url' => tag[0] ??null,
'adtype' => tag[1] ?? null,
'sitecode' => tag[2] ?? null,
'category' => tag[3] ?? null,
'type' => tag[4] ?? null,
'channel' => tag[5],
'product' => tag[6] ?? null,
'phase' => tag[7] ?? null,
'campaign' => tag[8],
'media' => tag[9] ?? null,
'creative' => tag[10] ?? null,
'segment' => tag[11] ?? null,
];
}, $cmp->data->tags->rows);
Changed Code
$columns = $tagData->columns;
$rows = $tagData->rows;
array_map(function($row) use($columns) {
$el = [];
foreach($columns as $ci=>$colname) {
$el[$colname] = $row[$ci] ?? null;
}
}, $rows);
Same when updating and saving data
$cmp->data->tags = $body;
$cmp->save();
return $this->response->json($cmp->data->tags);
=> Without thinking of columns and rows, just save as it is.
No need to think about finding tags to be updated.
반응형
'꼬꼬마 개발자 노트 > PHP' 카테고리의 다른 글
getParsedBody() 와 getBody() + Postman에서 test (0) | 2021.12.14 |
---|---|
변수 VS 상수 , 컴파일 시, 런타임시 (0) | 2021.12.10 |
PHP의 Magic Method (0) | 2021.12.03 |
PHP 에러 : Array to string conversion in php (0) | 2021.11.29 |
Comments