php - 隐藏 sql 结果列并在单击时显示在下表中

标签 php javascript mysql show-hide

我有一个显示 SQL 结果的表,但是我希望该表显示某些结果,并在单击时在表下方的 div 标记中显示更多结果。到目前为止,我有这段显示“标题”和“电子邮件”的代码以及将触发 JS 函数并在 div 标记中显示“详细信息”的第 3 列...如何使用 JavaScript 显示特定详细信息并隐藏单击第二行详细信息并替换第一行时的那些详细信息?

while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
        <td><?php echo $rows['title']; ?></td>
        <td><?php echo $rows['email']; ?></td>
        <td><a href="#" onClick="moreDetails();">More details...</a></td>
    </tr>

编辑: 在收到评论后,这是我的表格的完整代码,其中包含 id 为“details”的 div 元素

<table>
    <tr>
        <td><strong>Investment Title</strong></td>
        <td><strong>Email</strong></td>
        <td><strong>Details</strong></td>
    </tr>

<?php

    // Start looping table row
    while($rows=mysql_fetch_array($result)){
?>
    <tr>
        <td><?php echo $rows['title']; ?></td>
        <td><?php echo $rows['email']; ?></td>
        <td><a href="#" onClick="viewInvestor();">More details...</a></td>
    </tr>
<?php
    // Exit looping and close connection
}
    mysql_close();
?>
    <tr>
</tr>
</table>
<div id="detail"></div>

最佳答案

我不确定这是否是你想要做的,但你可以尝试这样的事情。希望对您有所帮助

HTML

<table>
    <tr>
        <td><strong>Investment Title</strong></td>
        <td><strong>Email</strong></td>
        <td><a href='#' id='show_details'>More Details</a></td>
    </tr>
    <tr>
        <td><?php echo $rows['title']; ?></td>
        <td><?php echo $rows['email']; ?></td>
        <td id='details'><?php echo $rows['details'];?></td>
    </tr>
</table>

Javascript - JQuery

$(document).ready(function()
{
    $('#details').hide(); //on ready hide the td details

    $('#show_details').click(function()
    {
        $('#details').show();
    });
});


更新

你的意思是这样 SEE MY FIDDLE

关于php - 隐藏 sql 结果列并在单击时显示在下表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16974004/

相关文章:

php - 使用 PHP、Javascript 和 JSON 创建下拉过滤器

javascript - 理解/使用回调函数时出现问题

php - mysqli_fetch_array() 期望参数 1 为 mysqli_result, boolean 值

c# - 如何通过iframe获取另一个页面的asp隐藏字段值

java - com.mysql.jdbc.exception.jdbc4.CommunicationsException : The last packet successfully received from the server was

php - 使用 PDO for PHP Xcode 将数据插入 MySQL

php - Jquery 和 php 无法将图像从文件夹加载到屏幕上

javascript - 在 reactjs 中添加带有查询字符串的外部 html 文件

javascript - 如何正确获得响应ajax?

asp.net - 无法检索元数据