Return html table from PHP using JQuery/AJAX
<p>I am going crazy trying to figure out how to display a table in a div tag after a user selects a select option.</p>

<p>JQuery/AJAX</p>

<pre><code>$('#months').change(function() {

                  var month_sent = $('#months option:selected').text();

                  $.ajax ({
                      type: "GET",
                      dataType: 'text',
                      url: "db_connect.php",
                      data: "dept_sent=" + dept_sent + "&amp;month_sent=" + month_sent + "&amp;year_sent=" + year_sent,
                      success: function(data) {
                          $('#incident_table').html(data);
                      },
                      error: function() {
                        alert("Error!");
                      }

                  });
              });
</code></pre>

<p>PHP</p>

<pre><code>  if ($dept &amp;&amp; year &amp;&amp; $month) {
      $query = "SELECT date,dept,area_name,ticket,description,resolution FROM incidents WHERE (dept = '$dept') AND (YEAR(date) = '$year') AND (MONTH(date) = '$month')";
      $query_image = "SELECT image_content FROM images WHERE dept_name = '$dept' AND year = '$year' AND month = '$month'";

      $result = mysql_query($query);
      $result_image = mysql_query($query_image);

      while ($row = mysql_fetch_assoc($result)) {
         // foreach ($row as $value) {
              $incident .= '&lt;tr&gt;&lt;td&gt;'.$row['date'].'&lt;/td&gt;&lt;td&gt;'.$row['dept'].'&lt;/td&gt;&lt;td&gt;'.$row['area_name'].'&lt;/td&gt;&lt;td&gt;'.$row['ticket'].'&lt;/td&gt;&lt;td&gt;'.$row['description'].'&lt;/td&gt;&lt;td&gt;'.$row['resolution'].'&lt;/td&gt;&lt;/tr&gt;';
          //}
      }
      echo $incident;
  }
</code></pre>

<p>All i need to do is be able to display the table inside of the "incidents" div tag</p>

<p>Edit:</p>

<pre><code>&lt;div style="border: 1px solid black; width:310px; height: 310px;" name="incidents" id="incidents"&gt;
      &lt;table id="incident_table"&gt;
      &lt;/table&gt;
  &lt;/div&gt;
</code></pre>

<p>Please help! :(</p>
