title: PHP, Classes and Objects
body: <p>I,m trying to list all the names from a  json database to html using a class. the html output should look something like this:-</p>
  
  <blockquote>
    <p><strong>Characters</strong></p>
    
    <ul>
    <li>name: John</li>
    <li>name: Sarah</li>
    <li>name: Michael</li>
    </ul>
  </blockquote>
  
  <p>I've managed to reach this far with my code. I know this code is not finished or it is has errors but I'm still a beginner and learning. Can you please help me get this code to work? </p>
  
  <p><strong>Json database file</strong></p>
  
  <blockquote>
    <p>databas.json</p>
  </blockquote>
  
  <pre><code>{
  "results": [
      {
          "name": "John",
          "height": "182 cm",
          "mass": "80 kg",
      },
      {
          "name": "Sarah",
          "height": "165 kg",
          "mass": "60 cm",
      },
      {
          "name": "Michael",
          "height": "178 cm",
          "mass": "75 kg",
      },
      ]
  }
  </code></pre>
  
  <p><strong>Index file</strong></p>
  
  <blockquote>
    <p>index.php</p>
  </blockquote>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
  
          &lt;title&gt;Character&lt;/title&gt;
  
      &lt;/head&gt;
  
      &lt;body style="margin-bottom:20em;"&gt;
          &lt;h1&gt;Characters&lt;/h1&gt;
              &lt;?php include('characters.php'); ?&gt;
  
              &lt;?php 
              $data = file_get_contents("databs.json");
              $data = json_decode($data, true);
  
              echo '&lt;pre&gt;';
              print_r($data);
              echo '&lt;/pre&gt;';
  
              ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Class code</strong></p>
  
  <blockquote>
    <p>characters.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  
  class Character {
  
          private $name;
  
  public function __construct($name) {
              $this-&gt;name = $name;
  
          }
  public function getName($name){
          return $this-&gt;name;
          }
  
  }
   ?&gt;
  </code></pre>