title: How to add a button or a link that sorts the data?
body: <p>In following code, how can I add a button or a link that sorts the data by 'name'?</p>
  
  <p>The following code is just an example, a modified version of code that I found from <a href="http://fwebde.com/php/sqlite-php/" rel="nofollow">http://fwebde.com/php/sqlite-php/</a> . The structure of the code is so enjoyable that I would like to improve it with a sorting-element.</p>
  
  <p>Thanks!</p>
  
  <pre><code>&lt;?php
  $db = new PDO('sqlite:db.db');
  if (isset($_POST['name']) &amp;&amp; isset($_POST['message'])) {
  try {
      $stmt = $db-&gt;prepare("INSERT INTO messages (name, message) VALUES (:name, :message);");
      $stmt-&gt;bindParam(':name', $name);
      $stmt-&gt;bindParam(':message', $message);
  
      $title = $_POST['name'];
      $content = $_POST['message'];
      $stmt-&gt;execute();
  } catch (Exception $e) {
      die ($e);
  }
  }try {
  $posts = $db-&gt;prepare('SELECT * FROM messages;');
  $posts-&gt;execute();
  } catch (Exception $e) {
  die ($e);
  }
  
  ?&gt;
  
  &lt;?php while ($post = $messages-&gt;fetchObject()): ?&gt; 
   &lt;?php echo $post-&gt;name ?&gt;
   &lt;?php echo $post-&gt;message ?&gt;
  &lt;?php endwhile; ?&gt;
  
  &lt;form action="" method="post"&gt;
      &lt;label for="name"&gt;Name:&lt;/label&gt;
      &lt;input type="text" name="name" /&gt;
      &lt;textarea name="message" rows="8" cols="50"&gt;&lt;/textarea&gt;
      &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>