doubu5035 2016-01-28 19:58 采纳率: 100%
浏览 34

数据库未正确回显到表中[重复]

This question is an exact duplicate of:

My table is supposed to have both a checkbox sum function whilst also being able to sort the data by its headers.

My current output based on the code below is this.

Current Output

Not sure what what exactly is my mistake?

 <?php
    include('session.php');
    ?>

    <?php
        include('connect1.php');
        $retrieve = $db->prepare("SELECT count(*) FROM Asset1");
        $retrieve->execute();
        $fetchrow = $retrieve->fetch(PDO::FETCH_NUM);
        $calculated=$fetchrow[0];
    ?>

    <script type="text/javascript">

        function UpdateCost() {
            var sum = 0;
            var gn, elem;
            for (i=0; i<<?php echo $calculated ?>; i++) {
                gn = 'sum_m_'+i;
                elem = document.getElementById(gn);
                if (elem.checked == true) { sum += Number(elem.value); }
            }
            document.getElementById('totalcost' ).value = sum.toFixed(0);
        }
        window.onload=UpdateCost

    </script>


    </div>



            <div class="cleaner"></div> 
        </div>

        <div id="templatemo_content">
            <div id="profile">
                <b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b>
                <b id="logout"><a href="logout.php">Log Out</a></b>
    <center>


    Total Cost : <input type="text" name="sen" id="totalcost" value="" />


    <h2>Overview Of Assets</h2>

        <table cellpadding="0" cellspacing="0" border="0" id="table" class="sortable">
            <thead>
                <tr>


                    <th><h3>Asset ID</h3></th>  
                    <th><h3>Vendor</h3></th>
                    <th><h3>Hardware</h3></th>
                    <th><h3>Cost</h3></th>
                    <th><h3>Date Of Purchase</h3></th>

                </tr>
            </thead>
            <tbody>

            <?php
                        // include('connect1.php'); you already included this file
                $result = $db->prepare("SELECT * FROM Asset1");
                $result->bindParam(':userid', $res);
                $result->execute();
                for($i=0; $row = $result->fetch(); $i++){
                ?>

                <?php
                while 
                ?>

                <tr>

                    <td><?php echo $row['Asset_ID']; ?></td>
                    <td><?php echo $row['Vendor_Name']; ?></td>
                    <td><?php echo $row['Hardware_ID']; ?></td>
                    <td><?php echo $row['Asset_Cost']; ?></td>
                    <td><?php echo $row['DateOfPurchase']; ?></td>
                    <th><h3><INPUT TYPE="checkbox" NAME="items[]" value="<?php echo $row['Asset_Cost'] ?>" id="sum_m_<?php echo $i ?>" onclick="UpdateCost()"></h3></th>


                </tr>

                ?>
                </tbody>
                </table>



                }
            ?>

            </tbody>
      </table>
        <div id="controls">
            <div id="perpage">
                <select onchange="sorter.size(this.value)">
                <option value="5">5</option>
                    <option value="10" selected="selected">10</option>
                    <option value="20">20</option>
                    <option value="50">50</option>
                    <option value="100">100</option>
                </select>
                <span>Entries Per Page</span>
            </div>
            <div id="navigation">
                <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
            </div>
            <div id="text">Displaying Page <span id="currentpage"></span> of <span id="pagelimit"></span></div>
        </div>

        <script type="text/javascript" src="script.js"></script>
        <script type="text/javascript">
      var sorter = new TINY.table.sorter("sorter");
        sorter.head = "head";
        sorter.asc = "asc";
        sorter.desc = "desc";
        sorter.even = "evenrow";
        sorter.odd = "oddrow";
        sorter.evensel = "evenselected";
        sorter.oddsel = "oddselected";
        sorter.paginate = true;
        sorter.currentid = "currentpage";
        sorter.limitid = "pagelimit";
        sorter.init("table",1);
      </script>


    <br>
    <br>
    <input type="button" name="export" value="Export Data into Excel"onclick="window.location.href='http://mp04.bit-mp.biz/FinalPresentation/Assetexport.php'"/> 
    <br>
    <br>
    <form name="getcvs" action="reportAsset.php" method="POST" /> <input type="submit" name="submitpdf" value="Download pdf file" />


      <br>
      <br>
    <input type="button" value="Add New Asset" onclick="window.location.href='http://mp04.bit-mp.biz/FinalPresentation/AssetAdd.php'" /> <input type="button" value="Update Asset" onclick="window.location.href='http://mp04.bit-mp.biz/FinalPresentation/AssetBeforeUpdate.php'" /> <input type="button" value="Delete Asset" onclick="window.location.href='http://mp04.bit-mp.biz/FinalPresentation/AssetDelete2.php'" /> <input type="button" value="Search Asset" onclick="window.location.href='http://mp04.bit-mp.biz/FinalPresentation/Assetsearch.php'" />
    <div id="templatemo_footer">
            <ul class="footer_list">
                <li><a href="http://mp04.bit-mp.biz/FinalPresentation/profile.php" class="current">Home</a></li>
                <li><a href="http://www.orangetee.com" class="last">OrangeTee</a></li>

            </ul> 

            <div class="margin_bottom_10"></div>      
            Copyright © 2016 Asset Management System 
    </div> 


    </html>
</div>
  • 写回答

1条回答 默认 最新

  • duandi1919 2016-01-28 20:43
    关注

    Your HTML is malformed: you have fewer cells in your table's header than in its body, the form tag isn't closed, and so on. Any of these may cause problems with the CSS and/or JavaScript used by your sorting library. So as a starting point, validate your HTML and address each issue, e.g. use https://validator.w3.org/

    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。