在表格上显示待定日期

时间:2018-05-16 06:13:25

标签: php html mysqli

当我转到索引页面时,我希望它显示表格中从所需日期到当前日期有多少待处理天数。这是我的index.php,它给出了一个错误“致命错误:在第93行的C:\ xampp \ htdocs \ Material \ index.php中调用boolean上的成员函数fetch_assoc()”< / p>

第93行 - &gt; while($ row = $ result-&gt; fetch_assoc()){

<?php

/* showing table */

                $sql = "SELECT * FROM main SET PendDays = CURRENT_DATE - RequiredDate ORDER BY ReqstDate DESC"
                    or die("Failed to query database" .mysqli_error());
                $result = $link->query($sql);    

                while ($row = $result->fetch_assoc()) {

                    print "<tr>"; 
                    print "<td >" . $row['ID'] . "</td>";
                    print "<td >" . $row['ReqstDate'] . "</td>";
                    print "<td ><a href=\"ReqOrdNum.php?ReqOrdNum={$row['ReqOrdNum']}\" target=\"_blank\">"  . $row['ReqOrdNum'] . "</a></td>";                    
                    print "<td ><a href=\"Location.php?Location={$row['Location']}\" target=\"_blank\">"  . $row['Location'] . "</a></td>";
                    print "<td ><a href=\"Description.php?Description={$row['Description']}\" target=\"_blank\">"  . $row['Description'] . "</a></td>"; 
                    print "<td >" . $row['Unit'] . "</td>";
                    print "<th >" . $row['Quantity'] . "</th>";
                    print "<th >" . $row['SupQty'] . "</th>";
                    print "<td >" . $row['RequiredDate'] . "</td>";
                    print "<td >" . $row['PendDays'] . "</td>";
                    print "<th >" . $row['BalanceQty'] . "</th>";
                    print "<th >" . $row['Unitprice'] . "</th>";
                    print "<th >" . $row['Totalamount'] . "</th>";
                    print "<td >" . $row['InvcNum'] . "</td>";
                    print "<td >" . $row['GRNNum'] . "</td>";
                    print "<td >" . $row['Remarks'] . "</td>";
                    print "<th ><a href=\"Status.php?Status={$row['Status']}\" target=\"_blank\">"  . $row['Status'] . "</a></th>";
                    print "</tr>"; 

                    }

?> 

3 个答案:

答案 0 :(得分:2)

所以有一些问题:首先在PHP代码中,您正在检查"SELECT ... "是否与or die...子句相等,而$link->query($sql)子句实际上应该在{$sql = "SELECT ... "; $result = $link->query($sql) or die("Failed to query database" .mysqli_error()); 子句上1}}陈述。即。

$result

一旦你以正确的方式得到这个,你就会看到你看到错误的原因是查询失败了,所以SET是假的,而不是结果集。

这会导致另一个问题,即您的查询。 SELECT中没有$sql = "SELECT *, DATEDIFF(CURDATE(), RequiredDate) AS PendDays FROM main ORDER BY ReqstDate DESC"; 。你可能想要的是:

$sql = "SELECT * FROM main SET PendDays = CURRENT_DATE - RequiredDate ORDER BY ReqstDate DESC" or die("Failed to query database" .mysqli_error());
$result = $link->query($sql);    

总而言之,改变

$sql = "SELECT *, DATEDIFF(CURDATE(), RequiredDate) AS PendDays FROM main ORDER BY ReqstDate DESC";
$result = $link->query($sql) or die("Failed to query database" .mysqli_error());

到此:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return true
} // this method is deprecated in iOS 9 https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application

答案 1 :(得分:0)

您的SQL查询中出现错误。这就是以下声明返回false的原因:

implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-building:0.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.12.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.5.2'

我认为你应该重做这个:

$result = $link->query($sql); 

答案 2 :(得分:0)

试试这个,

$today = new DateTime();
$sql = "SELECT * FROM main ORDER BY ReqstDate DESC"
        or die("Failed to query database" .mysqli_error());

$result = $link->query($sql);    

while ($row = $result->fetch_assoc()) {
    $date2 = new DateTime($row['RequiredDate']);
    print "<tr>"; 
    print "<td >" . $row['ID'] . "</td>";
    print "<td >" . $row['ReqstDate'] . "</td>";
    print "<td ><a href=\"ReqOrdNum.php?ReqOrdNum={$row['ReqOrdNum']}\" target=\"_blank\">"  . $row['ReqOrdNum'] . "</a></td>";                    
    print "<td ><a href=\"Location.php?Location={$row['Location']}\" target=\"_blank\">"  . $row['Location'] . "</a></td>";
    print "<td ><a href=\"Description.php?Description={$row['Description']}\" target=\"_blank\">"  . $row['Description'] . "</a></td>"; 
    print "<td >" . $row['Unit'] . "</td>";
    print "<th >" . $row['Quantity'] . "</th>";
    print "<th >" . $row['SupQty'] . "</th>";
    print "<td >" . $row['RequiredDate'] . "</td>";
    print "<td >" . $date2->diff($today)->format("%a"); . "</td>";
    print "<th >" . $row['BalanceQty'] . "</th>";
    print "<th >" . $row['Unitprice'] . "</th>";
    print "<th >" . $row['Totalamount'] . "</th>";
    print "<td >" . $row['InvcNum'] . "</td>";
    print "<td >" . $row['GRNNum'] . "</td>";
    print "<td >" . $row['Remarks'] . "</td>";
    print "<th ><a href=\"Status.php?Status={$row['Status']}\" target=\"_blank\">"  . $row['Status'] . "</a></th>";
    print "</tr>"; 
}