Php 使用Ajax从数据库隐藏/显示表列
我找到了一种连接到数据库并检索数据的方法,但当我试图隐藏/显示我的表列时,它似乎不起作用,我甚至不知道使用Ajax是否可行 我的Html:Php 使用Ajax从数据库隐藏/显示表列,php,jquery,mysql,ajax,database,Php,Jquery,Mysql,Ajax,Database,我找到了一种连接到数据库并检索数据的方法,但当我试图隐藏/显示我的表列时,它似乎不起作用,我甚至不知道使用Ajax是否可行 我的Html: <table class="footable" id="masterChart"> <thead><tr><th data-class="expand" class="account">Account Number</th><th>Account Descript
<table class="footable" id="masterChart">
<thead><tr><th data-class="expand" class="account">Account Number</th><th>Account Description</th><th>Level 01</th><th>Level 02</th><th>Level 03</th><th>Level 04</th><th>Tax</th><th>YTD - Current</th><th>YTD - Prior</th><th>MTD - Current</th><th>MTD - Prior</th></tr></thead>
<?php $index = 0?>
<?php while ($row = mysql_fetch_assoc($result)):?>
<tr<?php echo $index++ % 2 ? ' class="even"' : ''?>>
<td><?php echo $row['accountNumber']?></td>
<td><?php echo $row['accountDescription']?></td>
<td><?php echo $row['accountLevel1']?></td>
<td><?php echo $row['accountLevel2']?></td>
<td><?php echo $row['accountLevel3']?></td>
<td><?php echo $row['accountLevel4']?></td>
<td><?php echo $row['id']?></td>
<td><?php echo $row['id']?></td>
<td><?php echo $row['id']?></td>
<td><?php echo $row['id']?></td>
<td><?php echo $row['id']?></td>
</tr>
<?php endwhile?>
</table>
我将上面的ajax.js文件包括在我的文件中,如下所示:
<script src="ajax/ajax.js" type="text/javascript"></script>
如果有人能帮忙,我会非常感激!如果有人有其他方法获取数据库信息并为用户隐藏特定的列、表,我也很感激。您能提供HTML的完整结构吗? 在调用ajax请求之前,您是否从任何表开始 除此之外,请尝试更新以下内容:
if (show == 0){
$(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
}
为此:
if (show == 0){
$(table +' td:nth-child(' + column + '),' + table + ' th:nth-child(' + column + ')').hide();
}
好吧,我说对了:
我把profile.class.php添加错了,应该是../classes/profile.class.php
除此之外,jquery是错误的
这:
$(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
需要这样做:
$('#'+ table +' td:nth-child(' + column + '), #' + table + ' th:nth-child(' + column + ')').hide();
它根据用户的选择查找显示/隐藏值:)我在主要问题中添加了html表格信息。。我编辑了ajax脚本,但它仍然不起作用。。
$(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
$('#'+ table +' td:nth-child(' + column + '), #' + table + ' th:nth-child(' + column + ')').hide();