title: display Mysql query results on onClick() using Ajax
body: <p>I'm beginner with Ajax scripts and I'm trying to build a script that displays Mysql queries results when the user clicks on a link.
  I've thought about using the onClick() function calling an Ajax script.
  Here is my code :</p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/course/format/topics/ajax.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;div id="stitre"&gt;
      &lt;a href="#" onclick="display()" id="link1" class="link"&gt; Link 1&lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="one"&gt; &lt;/div&gt;
  &lt;div id="stitre"&gt;
      &lt;a href="#" onclick="display()" id="link2" class="link"&gt; Link 2&lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="one"&gt; &lt;/div&gt;
  </code></pre>
  
  <p>My ajax.js code :</p>
  
  <pre><code>$(document).ready(function() { 
  for (var i=1; i&lt;3; i++) {
      var id = document.getElementById("#link" + i);
      function display() {
          $.ajax({
              async: false,
              type: "POST",
              url: "myphp.php",
              data: "id=" + id,
              dataType: "json",
              success: function(msg) {
                  if(msg.success) {
              $("#one").html(msg);
                  } else {
                      alert("error");
                  }
              }
          });
      };
  }
  }); 
  </code></pre>
  
  <p>and finaly, myphp.php :</p>
  
  <pre><code>&lt;?php
      require_once('config.php');
      mysql_connect($CFG-&gt;dbhost, $CFG-&gt;dbuser, $CFG-&gt;dbpass);
      mysql_select_db($CFG-&gt;dbname);
      mysql_query("SET NAMES 'utf8'");
  
      $id = $_GET['id'];
      if($return = display($id)) {
          echo "success";
      } else {
          echo "error";
      }
      echo json_encode($reply);
  ?&gt;
  </code></pre>
  
  <p>For now, nothing is displayed when I click on the links.</p>