title: Retrieving Data with Jquery, AJAX, and PHP from a MySQL Database
body: <p>I am trying to figure out how to retrieve data from a MySQL database using an AJAX call to a PHP page.  I have been following this tutorial</p>
  
  <p><a href="http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/" rel="nofollow">http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/</a></p>
  
  <p>But i cant figure out how to get it to send back json data so that i can read it.</p>
  
  <p>Right now I have something like this:</p>
  
  <pre><code>$('h1').click(function() {
              $.ajax({
                  type:"POST",
                  url: "ajax.php",
                  data: "code="+ code,
                  datatype: "xml",
                  success: function() {
  
                  $(xml).find('site').each(function(){
                      //do something
                  });
              });
  
  
          });
  </code></pre>
  
  <p>My PHP i guess will be something like this</p>
  
  <pre><code>    &lt;?php
  
      include ("../../inc/config.inc.php");
  
      // CLIENT INFORMATION
  
      $code        = htmlspecialchars(trim($_POST['lname']));
  
      $addClient  = "select * from news where code=$code";
      mysql_query($addClient) or die(mysql_error());
  
  ?&gt;
  </code></pre>
  
  <p>This tutorial only shows how to insert data into a table but i need to read data.  Can anyone point me in a good direction?</p>
  
  <p>Thanks,</p>
  
  <p>Craig</p>