0

在用户选择选择选项后,我想弄清楚如何在 div 标签中显示表格,我快疯了。

jQuery/AJAX

$('#months').change(function() {

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

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

                  });
              });

PHP

  if ($dept && year && $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 .= '<tr><td>'.$row['date'].'</td><td>'.$row['dept'].'</td><td>'.$row['area_name'].'</td><td>'.$row['ticket'].'</td><td>'.$row['description'].'</td><td>'.$row['resolution'].'</td></tr>';
          //}
      }
      echo $incident;
  }

我需要做的就是能够在“事件” div 标签内显示表格

编辑:

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

请帮忙!:(

4

3 回答 3

0

您在 PHP 的第一行中缺少$ before year

改变这一行:
if ($dept && year && $month) {

对此:
if ($dept && $year && $month) {

首先尝试单独运行 PHP 文件以检查它是否正常工作。

于 2012-04-26T16:52:16.413 回答
0

尝试将您的 php 更改为:

    if ($dept && year && $month) {
      print_r(1);exit;
      $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 .= '<tr><td>'.$row['date'].'</td><td>'.$row['dept'].'</td><td>'.$row['area_name'].'</td><td>'.$row['ticket'].'</td><td>'.$row['description'].'</td><td>'.$row['resolution'].'</td></tr>';
          //}
      }
      echo $incident;
  } else print_r(0);exit;

然后移动 print_r(1); 向下命令,直到您发现问题所在的行

于 2012-04-26T17:08:29.447 回答
0

将动态内容插入div而不是插入空/不完整table结构

 success: function(dataHTML) {
      $('#incidents').html(dataHTML);
 },

并在 php

echo '<table id="incident_table">'.$incident.'</table>';

还阅读了关于 SQL 注入的其他评论和一年中缺少的 $

于 2012-04-26T17:08:41.023 回答