我有一张表 A 。单击此表的任何行时,我需要显示其他表 B 的数据(具有关系键 s_id)。
例如: 表A: 身份证号码 姓名 年龄 1 ABC 12 2 xyz 13
表B: 身份证 性别 添加 1 F agh 2M qwer
我希望我的输出为:表A应该按原样打印,然后单击表A行,例如单击表A的第一行应该给出表B的第一行,点击A的第二行应该给出第二行B 排等。是否可以?请帮帮我
我的代码是:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#report tr:odd").addClass("odd");
$("#report tr:not(.odd)").hide();
$("#report tr:first-child").show();
$("#report tr.odd").click(function(){
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
});
//$("#report").jExpand();
});
</script>
<body>
<table border="1"id="report">
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Place</th>
</tr>
<tr>
<td>uda</td>
<td>22</td>
<td>F</td>
<td>lore</td>
</tr>
<tr>
<td colspan="4">
blah blah
<br />
:(
</td>
</tr>
<tr>
<td>ish</td>
<td>20</td>
<td>F</td>
<td>ore</td>
</tr>
<tr>
<td colspan="4">
<table width="335" s >
<tr>
<td>uda</td>
<td>aixa</td>
<td>diidi</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
此代码打印以 和 形式键入的数据。这里的另一个问题是,当我尝试使用 mysql 查询打印行时,它不起作用。
<?php
$result = mysql_query("SELECT * FROM A");
while($row=mysql_fetch_array($result)){ ?>
<td><?php echo $row["source_id"]; ?></td>
<td><?php echo $row["escl_status"]; ?></td>
<td><?php echo $row["escl_notice"]; ?></td>
</tr>
<?php
}
?>
请帮助我:(
最佳答案
您需要添加<tr>
在 while 循环中,
<?php
$result = mysql_query("SELECT * FROM A");
while($row=mysql_fetch_array($result)){ ?>
<tr> <!-- add this tr -->
<td><?php echo $row["source_id"]; ?></td>
<td><?php echo $row["escl_status"]; ?></td>
<td><?php echo $row["escl_notice"]; ?></td>
</tr>
<?php
}
?>
同时更改.odd
至:odd
在你的 jquery 选择器中,
$("#report tr:odd").click(function(){ // :odd not .odd
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
});
关于php - 展开表格中单击行的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28406325/