title: How to return database query into ajax?
body: <p>I want to check if a user has favourited an item but I'm unsure how to return the result of a database query to ajax. </p>
  
  <p>I will show different html depending on the result.</p>
  
  <p>Php</p>
  
  <pre><code>$query = "SELECT itemID from favourites WHERE userid = '" . $user. "'";
  $result = mysql_query($query);
  
  echo json_encode($result);
  </code></pre>
  
  <p>Jquery</p>
  
  <pre><code>$.ajax({
    url: "inc/functions.php",
    type: "POST",
    data: {--result--},
    success: function () {
  
        // if result found in database 
           $('favourite').hide();
  
        // if result not found
           $('favourite').show();
        }
  });
  </code></pre>
  
  <p>I can't figure out how to display $result in the jquery code. </p>
  
  <p>Any help much appreciated. </p>