title: How to properly format sql json as desired
body: <p>Basically,I want to fetch data from mysql and format it into json like this:</p>
  
  <pre><code>[
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
  
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
     [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
    [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
     [
      "title" =&gt; "first",
      "uploader" =&gt; "root"
    ],
  
  ]
  </code></pre>
  
  <p>I used this code:</p>
  
  <pre><code>&lt;?php
  require 'config.php';
  
              $query = $_GET['q'];
              if ($query==null) {
                  exit('No query');
              }
  
  $sql = "SELECT title,uploader FROM `uploads_public` WHERE Title =:query ";
  
          if($stmt = $pdo-&gt;prepare($sql)){
              // Bind variables to the prepared statement as parameters
              $stmt-&gt;bindParam(":query", $query, PDO::PARAM_STR);
  
  
  
  
              // Attempt to execute the prepared statement
              if($stmt-&gt;execute()){
                 echo "Your search $query has the following results(normal json):&lt;br&gt;";
                 $results = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
                 $json = json_encode($results);
                 echo($json).'&lt;br&gt;';
  
                 echo "While it has the following results when replaced&lt;br&gt;";
                 echo  str_replace('}',']',str_replace(':','=&gt;',str_replace('{', '[', "$json")));
  
  
  
  
  
           } else{
                  echo "Something went wrong. Please try again later. &lt;br&gt;"; print_r($stmt-&gt;errorInfo());
              }
                      // Close statement
          unset($stmt);
          unset($pdo);
          }
  
  
  
  
  
     else{
      echo "No input";
  } 
  </code></pre>
  
  <p>But rather than what I wanted(mentioned above),i got this:</p>
  
  <p>[["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"],["title"=>"first","uploader"=>"root"]]</p>
  
  <p>It looks ok,but the major problem is that I don't want all the results compressed together ,I want it exactly the way mentioned..with line breaks(new lines) after every ..<code>[</code>,<code>",</code> and so on </p>
  
  <p>Thanks</p>