2017-04-09 1 views
0

부트 스트랩 데이터 테이블을 사용하여 테이블의 API 데이터를 표시합니다. 데이터는 다음과 같습니다.php를 사용하여 json 배열을 반복하고 출력 HTML

{ 
    "response_status": { 
    "status_code": 0, 
    "status_message": [ 
     { 
     "reg_number": "123", 
     "company": "Company A", 
     "office": "Orlando", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     }, 
     { 
     "reg_number": "552", 
     "company": "Company B", 
     "office": "Miami", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     }, 
     { 
     "reg_number": "154", 
     "company": "Company C", 
     "office": "San Francisco", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     } 
    ] 
    } 
} 

저는 테이블의 API 데이터를 표시하기 위해 부트 스트랩 데이터 테이블을 사용합니다.

{ 
    "response_status": { 
    "status_code": 0, 
    "status_message": [ 
     { 
     "reg_number": "123", 
     "company": "Company A", 
     "office": "Orlando", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     }, 
     { 
     "reg_number": "552", 
     "company": "Company B", 
     "office": "Miami", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     }, 
     { 
     "reg_number": "154", 
     "company": "Company C", 
     "office": "San Francisco", 
     "phone_number": "28122312345", 
     "postal_address": "000", 
     "postal_code": "000" 
     } 
    ] 
    } 
} 
I need the result to output html as this: 

<table> 
<thead> 
    <tr> 
     <th>Reg No</th> 
     <th>Company</th> 
     <th>Office</th> 
     <th>Phone Number</th> 
     <th>Postal Address</th> 
     <th>Postal Code</th> 
    </tr> 
</thead> 

<tbody> 
    <tr> 
     <td>123</td> 
     <td>Company A</td> 
     <td>San Francisco</td> 
     <td>28122312345</td> 
     <td>000</td> 
     <td>000</td> 
    </tr> 
    <tr> 
     <td>552</td> 
     <td>Company B</td> 
     <td>Miami</td> 
     <td>28122312345</td> 
     <td>000</td> 
     <td>000</td> 
    </tr> 
    <tr> 
     <td>154</td> 
     <td>Company C</td> 
     <td>San Francisco</td> 
     <td>28122312345</td> 
     <td>000</td> 
     <td>000</td> 
    </tr> 
</tbody> 
<table> 

지금까지 나는이

<table> 
<thead> 
    <tr> 
     <th>Reg No</th> 
     <th>Company</th> 
     <th>Office</th> 
     <th>Phone Number</th> 
     <th>Postal Address</th> 
     <th>Postal Code</th> 
    </tr> 
</thead> 
<tbody> 
    <?php foreach($data->response_status->status_message as $message) : ?> 
    <tr> 
     <td><?php echo $message->reg_number; ?></td> 
     <td><?php echo $message->company; ?></td> 
     <td><?php echo $message->office; ?></td> 
     <td><?php echo $message->phone_number; ?></td> 
     <td><?php echo $message->postal_address; ?></td> 
     <td><?php echo $message->postal_code; ?></td> 
    </tr> 
    <?php endforeach; ?> 
</tbody> 
<table> 

하지만 그 작동하지 주위에 재생 한 다음은 데이터입니다. 이 문제를 해결할 수있는 해결 방법이 있습니까?

+0

데이터를'json_decode '하시겠습니까? 'json_decode'의 두 번째 매개 변수를 사용하여 연관 배열을 반환하려 했습니까? 당신이 얻고있는 오류는 무엇입니까? – Scopey

답변

0

모든 @Scopey 댓글을 달았 당신이 이미 다음 아무 잘못없는 수행 한 경우에만 여기에 누락 된

$json = file_get_contents('path/to/your/JSONfile.json'); 
    $data= json_decode($json); 

json_decode입니다, 잘 보인다.

관련 문제