duanjiyun7391 2016-11-30 12:06
浏览 76

使用jquery显示/隐藏div值

I have two tables which are related to each other using a common column called invoice_no. What I want to is something like this:-

To Show the data from one table at first like-> image 1

And then to Show Data Like This from second table When a user clicks VIEW button like-> image 2

How can i toggle the data from second table on click of the button VIEW in each rows of the table and not show them all at once, by using jquery..

Here's my code i have been using to view all the data at once:-

<?php

$mysqli= new mysqli("localhost","root","","store_records");
if($mysqli->connect_error)
die("Database connection failed ".$mysqli->connect_error);

$query_details = "select DATE_FORMAT(date, '%d-%m-%Y') as date, ID, invoice_no, balance, sub_total, vat_tax, grand_total from bill_details ORDER BY DATE_FORMAT(date, '%m-%d-%Y') DESC";
$result_details = $mysqli->query($query_details);
echo"<table id='products_table' border='1'>";
echo "<tr><th>Date</th><th>Invoice No</th><th>Balance</th><th>Sub Total</th><th>ADD V.A.T Tax</th><th>Grand Total</th></tr>";
while($row_details = $result_details->fetch_assoc())
{

echo "<tr><td>".$row_details['date']."</td><td>".$row_details['invoice_no']."</td><td>".$row_details['balance']."</td><td>".$row_details['sub_total']."</td><td>".$row_details['vat_tax']."</td><td>".$row_details['grand_total']."</td><td><input type='button' id='viewdetails' value='View'></td></tr>";

$query_records = "select * from bill_records where invoice_no='".$row_details['invoice_no']."'";
$result_records = $mysqli->query($query_records);
echo "<td colspan='15'>";
echo "<table border='1' width='100%'>";
echo "<tr><th>Item Name</th><th>Quantity</th><th>Pack</th><th>Batch</th><th>Expiry</th><th>M.R.P</th><th>Rate</th><th>VAT</th><th>DIS.</th><th>Amount</th></tr>";
while($row_records = $result_records->fetch_assoc())
{

echo "<tr><td>".$row_records['item_name']."</td><td>".$row_records['qty']."</td><td>".$row_records['pack']."</td><td>".$row_records['batch']."</td><td>".$row_records['expiry']."</td><td>".$row_records['mrp']."</td><td>".$row_records['rate']."</td><td>".$row_records['vat']."</td><td>".$row_records['discount']."</td><td>".$row_records['amount']."</td></tr>";

}
echo "</table>";
echo "</td>";
echo"</tr>";
}
echo "</table>";
?>

Thanking you for your help :)

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-11-30 12:17
    关注

    You will need to work with unique ids, in this case you can use the invoice_no field. If you define that unique id to the field you're using to show the field you are able to show them 1 by 1. You can see a simple example below, this example is using smarty variables.

    <style>
    .hide {
        display: none;
    }
    </style>
    
    {foreach $items as $item}
        <div class="block">
            <button id="button-{$item.id}">Show Field</button>
            <div class="hide" id="block-{$item.id}">
                Content {$item.id}
            </div>
        </div>
    {/foreach}
    
    <script type="text/javascript">
        $('[id^="button-"]').click(function () {
            var id_parts = $(this).attr('id').split('-');
            $('#block-' + id_parts[1]).fadeIn();
        });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多