Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <h1>Company list</h1>
- <p>Please select Company to see list of materials.</p>
- <?php
- // download company list
- $companylist = file_get_contents('http://193.142.112.220:8337/companyList');
- $array = json_decode($companylist);
- // create for every company list of materials
- foreach($array as $key => $company){
- $index = $key+1;
- echo $company->companyName . " " . $company->companyID. "<br />";
- $materialData = file_get_contents('http://193.142.112.220:8337/materialList?companyID='.$index);
- // echo str_replace - changing quotes to apostrophe
- ?>
- <button class="btn btn-default" onclick="myFunction(<?php echo $index; ?>, <?php echo str_replace('"', "'", $materialData);?>)">
- <?php echo $company->companyName;?> </button>
- <?php
- }
- ?>
- <!-- show company table -->
- <div id="showData"></div>
- <script>
- // function add records to table
- function CreateTable(){
- $('#showData').html('<table><tbody><tr><th>Materiał </th><th>ID Materiału </th><th>ID firmy </th><th>Nazwa firmy </th><th>Opis materiału </th></tr></tbody></table>');
- }
- function addRecordsToTable(a,b,c){
- if($('table') != ''){
- $('table').append('<tr><td>'+a+'</td><td>'+b+'</td><td>'+c+'</td><td></td><td></td></tr>');
- }
- }
- // function for viewing decode json data from url
- function myFunction(x, data) {
- CreateTable();
- var text = "";
- data.forEach(function(entry){
- ///text = text + "<br />" + entry.name + " " + entry.ID + " " + entry.companyID;
- addRecordsToTable(entry.name,entry.ID,entry.companyID);
- });
- //document.getElementById(x).innerHTML = text;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement