Advertisement
Guest User

koparek

a guest
Sep 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>Company list</h1>
  6. <p>Please select Company to see list of materials.</p>
  7.  
  8. <?php
  9. // download company list
  10. $companylist = file_get_contents('http://193.142.112.220:8337/companyList');
  11. $array = json_decode($companylist);
  12. // create for every company list of materials
  13. foreach($array as $key => $company){
  14.     $index = $key+1;
  15.     echo $company->companyName . "  " . $company->companyID. "<br />";
  16.     $materialData = file_get_contents('http://193.142.112.220:8337/materialList?companyID='.$index);
  17. // echo str_replace - changing quotes to apostrophe
  18.     ?>
  19.     <button class="btn btn-default" onclick="myFunction(<?php echo $index; ?>, <?php echo str_replace('"', "'", $materialData);?>)">
  20.     <?php echo $company->companyName;?> </button>
  21.  
  22. <?php
  23. }
  24. ?>
  25. <!-- show company table -->
  26.     <div id="showData"></div>
  27. <script>
  28. // function add records to table
  29. function CreateTable(){
  30.  
  31.     $('#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>');
  32.  
  33. }
  34.  
  35. function addRecordsToTable(a,b,c){
  36.     if($('table') != ''){
  37.     $('table').append('<tr><td>'+a+'</td><td>'+b+'</td><td>'+c+'</td><td></td><td></td></tr>');
  38.     }
  39.  
  40. }
  41.  
  42. // function for viewing decode json data from url
  43. function myFunction(x, data) {
  44.     CreateTable();
  45.     var text = "";
  46.     data.forEach(function(entry){
  47.         ///text = text + "<br />" + entry.name + " " + entry.ID + " " + entry.companyID;
  48.         addRecordsToTable(entry.name,entry.ID,entry.companyID);
  49.  
  50.     });
  51.     //document.getElementById(x).innerHTML = text;
  52. }
  53. </script>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement