【问题标题】:Using HTML table cells as input [closed]使用 HTML 表格单元格作为输入 [关闭]
【发布时间】:2018-12-09 17:00:57
【问题描述】:

我对 php、HTML 和 mysql 还是很陌生。这是我第一次使用 HTML 表格。

我已经用 MySQL 表中的行填充了一个 HTML 表。我希望此表用作菜单,用户可以在其中单击具有适当日期的单元格。然后,该日期将作为会话变量传递,以使用另一个 .php 文件从 MySQL 表中的相应行中提取更多信息。

问题:如何从作为变量点击出来的表格单元格中获取日期?

到目前为止,下面是我的表格:

  <div div style="height:200px;width:350px;overflow:auto;">  
  <table class="table">   
      <tr>          
          </tr>   
          <?php 
            echo "<tbody>";
             while($result = mysqli_fetch_assoc($sql)) {
              echo "<tr>";
              echo "<td>". $result['iso_date'] . "</td>";
              echo "<td>". $result['lab_monitor'] . "</td>";
            }
            echo "</tr>";  
          ?>
  </table>
</div>

【问题讨论】:

标签: javascript php html ajax


【解决方案1】:

使用 Jquery 和 Ajax

HTML

<td data-id='".$result['iso_date']."'>
    <button class='date-button'>Reserve Book</button>
</td>

脚本

<script>
$('.date-button').click(function(){

    var iso_date = $(this).parent().data('id');

    $.ajax
    ({ 
        url: 'otherPhp.php',
        data: {"iso_date": iso_date},
        type: 'post',
        success: function(result)
        {
            alert(result);
        }
    });
});
</script>

确保导入 Jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>

或者你可以在没有 javascript 的情况下做这样的事情:

echo "<td><a href='whatEverURL.php?myParameter=".$result['iso_date']."'>". $result['iso_date'] . "</a></td>";

然后您可以使用$_GET['myParameter'] 读取URL 参数并在同一个php 文件中分配。

【讨论】:

  • 这就是答案。我使用了最后的回声语句,它就像一个魅力。感谢您的帮助!
  • np :-) 不客气
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 2016-06-10
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多