Advertisement
Riju18

no.96_get_json_data_from_json_file-php

Apr 30th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. db.php:
  2. --------
  3. --------
  4. <?php
  5. $host = "localhost";
  6. $user = "root";
  7. $pass = "";
  8. $db = "test";
  9.  
  10.   $connect = mysqli_connect( $host, $user, $pass, $db );
  11.   if ( !$connect ) {
  12.     mysqli_error( $connect );
  13.   }
  14.  ?>
  15.  
  16.  
  17. show_json.php:
  18. ---------------
  19. ---------------
  20. <?php
  21.   include 'db.php';
  22.  ?>
  23. <!DOCTYPE html>
  24. <html lang="en">
  25. <head>
  26.   <meta charset="UTF-8">
  27.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  28.   <meta http-equiv="X-UA-Compatible" content="ie=edge">
  29.   <title>show data</title>
  30.   <style media="screen">
  31.     table,th,tr,td{
  32.       border: 1px solid black;
  33.       border-collapse: collapse;
  34.       padding: 5px;
  35.     }
  36.   </style>
  37. </head>
  38. <body>
  39.   <?php
  40.      $data = file_get_contents("data.json");
  41.      // echo $data;
  42.      $data = json_decode( $data, true);
  43.      echo "<table>";
  44.      echo "<tr>";
  45.      echo "<th>"."firstname"."</th>";
  46.      echo "<th>"."lastname"."</th>";
  47.      echo "</tr>";
  48.      foreach ($data as $value) {
  49.        echo "<tr>";
  50.        echo "<td>".$value["firstname"]."</td>";
  51.        echo "<td>".$value["lastname"]."</td>";
  52.        echo "</tr>";
  53.        // if ( $value['firstname'] == "riju" ) {
  54.        //   echo "name found";
  55.        //   break;
  56.        // }
  57.      }
  58.      echo "</table>";
  59.    ?>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement