显示特定日期

时间:2016-04-07 11:31:24

标签: php mysqli

你能帮我一个忙吗?我被困在一个地方。我想在循环中显示特定日期的所有记录。

例如。我有8月29日的8条记录,然后我想显示29日游行的标题,并在div内显示29号游行的所有记录。

我有12次29次游行的记录和10次27次游行的10次记录。到目前为止,我已成功通过GROUP BY子句显示27个3月27日和3月29日的日期,但所有记录都没有在特定日期内显示

我没有显示3月29日的所有12条记录,而是每个日期只有1行。我附上截图和代码以便更好地理解。我得到的是:

enter image description here

正如您在上面所看到的,我每个日期只获得1行而不是与该日期相关的所有行

我想要的是:enter image description here

不好编辑哈哈...但是我希望它能让你清楚地了解我想要完成的事情。所有29行都通过循环行进,所有行都是27行进循环。我附上了代码......请看看可以做什么

代码(PHP& MYSQLI)

<?php

    $Prepare_Dealers_Purchases_Query = "SELECT * FROM `purchases` WHERE `DealerEmailAddress` = '$ShowDealerEmailAddress' GROUP BY `PurchaseDate` ORDER BY `InvoiceID` DESC";

    $Fire_Dealers_Purchases_Query = mysqli_query($CreateConnection, $Prepare_Dealers_Purchases_Query);

    if(mysqli_num_rows($Fire_Dealers_Purchases_Query) == 0) {
        echo "<div id='userFeedbackPanel' style='margin:15% auto;padding:10px;'><table id='feedbackDataStyling' cellspacing='5' cellpadding='5'><tr><td>You have not purchased any product yet</td></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr><td><a onClick=\"$.fn.openProductSelectionBox();\" class=\"StartShoppingButton\"><i class=\"fa fa-shopping-cart fa-lg\"></i>&nbsp;&nbsp;Start Shopping</a></td></tr></table></div>";
    } else {
        while($Show_Purchases = mysqli_fetch_array($Fire_Dealers_Purchases_Query, MYSQLI_ASSOC)) {

            if($Show_Purchases['SelectedProduct'] == "Regular Colours") {
                $Shade_Colour = $Show_Purchases['SelectedShade'];
                $Purchase_Date = $Show_Purchases['PurchaseDate'];

                $Prepare_Dealers_Purchases_As_Per_Date_Query = "SELECT * FROM `purchases` WHERE `DealerEmailAddress` = '$ShowDealerEmailAddress' AND `PurchaseDate` = '$Purchase_Date' ORDER BY `InvoiceID` DESC";

                $Fire_Dealers_Purchases_As_Per_Date_Query = mysqli_query($CreateConnection, $Prepare_Dealers_Purchases_As_Per_Date_Query);

                echo "<div align='left'>".$Show_Purchases['PurchaseDate']."</div><br>";
                while($Show_Purchases_As_Per_Date = mysqli_fetch_array($Fire_Dealers_Purchases_As_Per_Date_Query, MYSQLI_ASSOC)) {
                    echo "<div id='userFeedbackPanel'><table id='feedbackDataStyling' cellspacing='5' cellpadding='5'><tr><td style='background:$Shade_Colour;border-radius:5px;width:54px;height:64px;'></td><td>You purchased ".$Show_Purchases_As_Per_Date['SelectedQuantity']." boxes of ".$Show_Purchases_As_Per_Date['SelectedProduct']." worth <i class='fa fa-inr'></i> ".$Show_Purchases_As_Per_Date['FinalAmount']." by using ".$Show_Purchases_As_Per_Date['PaymentMethod']." of ".$Show_Purchases_As_Per_Date['BankName']." at ".$Show_Purchases_As_Per_Date['PurchaseTime']." on ".$Show_Purchases_As_Per_Date['PurchaseDate']."</td></tr></table></div><br>";
                    }
                } else {
                    $Product_Image = $Show_Purchases['SelectedProductImage'];

                    echo "<div align='left'>".$Show_Purchases['PurchaseDate']."</div><br><div id='userFeedbackPanel'><table id='feedbackDataStyling' cellspacing='5' cellpadding='5'><tr><td><img src='$Product_Image' width='54' height='64'></td><td>You purchased ".$Show_Purchases['SelectedQuantity']." boxes of ".$Show_Purchases['SelectedProduct']." worth <i class='fa fa-inr'></i> ".$Show_Purchases['FinalAmount']." by using ".$Show_Purchases['PaymentMethod']." of ".$Show_Purchases['BankName']." at ".$Show_Purchases['PurchaseTime']." on ".$Show_Purchases['PurchaseDate']."</td></tr></table></div><br>";

            }
        }
    }
?>

我正在使用2 while循环。 1循环获取所有日期和其他循环以获取该特定日期的行。请告诉我我犯错的地方。谢谢大家...

1 个答案:

答案 0 :(得分:0)

好像你要去那里:

else {
    $Product_Image = $Show_Purchases['SelectedProductImage'];

    echo "<div align='left'>".$Show_Purchases['PurchaseDate']."</div><br><div id='userFeedbackPanel'><table id='feedbackDataStyling' cellspacing='5' cellpadding='5'><tr><td><img src='$Product_Image' width='54' height='64'></td><td>You purchased ".$Show_Purchases['SelectedQuantity']." boxes of ".$Show_Purchases['SelectedProduct']." worth <i class='fa fa-inr'></i> ".$Show_Purchases['FinalAmount']." by using ".$Show_Purchases['PaymentMethod']." of ".$Show_Purchases['BankName']." at ".$Show_Purchases['PurchaseTime']." on ".$Show_Purchases['PurchaseDate']."</td></tr></table></div><br>";
}

此处没有while循环,因此只显示一行。添加与if语句中相同的while循环,它应该没问题:)