Как сделать OrderList с использованием SQL и PHP - PullRequest
0 голосов
/ 09 октября 2019

Меня попросили установить список внизу кода в алфавитном порядке, а другой - в порядке убывания.

Я пробовал rsort, array_reverse, collection, помещать список в новый массив и затемсортировать это.

  if (isset($Year)) {
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50), @effectiveYear 
    int
    set @ein = :EIN
    set @effectiveYear=:Year
    SELECT *
    FROM [Chamber].[dbo].[PrintedDoc]
  where ein = @ein and year(effectiveDate)=@effectiveYear and datetimePrinted `enter code here`= (select max(DateTimePrinted) from `PrintedComplianceDocuments p2 where p2.ein = @ein and `enter code 
  here`year(p2.effectiveDate)=@effectiveYear)");
    $statement->bindParam(":EIN", $EIN);
    $statement->bindParam(":Year", $Year);
} elseif (isset($EffectiveDate)) {
    # code...
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50), @effectiveDate 

    date
    set @ein = :EIN
    set @effectiveDate=:Date
    SELECT *
    FROM [Chamber].[dbo].[PrintedDoc]


    where ein = @ein and effectiveDate=@effectiveDate and datetimePrinted = `(select max(DateTimePrinted) from PrintedComplianceDocuments p2 where p2.ein 
    =@ein and p2.effectiveDate=@effectiveDate)");
        $statement->bindParam(":EIN", $EIN);


   $statement->bindParam(":Date", $EffectiveDate);
    } else {
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50)
    set @ein = :EIN
   select * from Chamber.dbo.PrintedDoc p1
  where EIN = @EIN and DateTimePrinted = (select max(dateTimePrinted) from PrintedeDoc p3 where p3.EIN = @EIN and p3.EffectiveDate = (select max(EffectiveDate) from PrintedDoc p2 where p2.EIN = @ein))");
    $statement->bindParam(":EIN", $EIN);
}
    $statement->execute();
    $DocumentListResult = $statement->fetchAll(PDO::FETCH_ASSOC);


    $statement = $server->prepare("SELECT Distinct EffectiveDate from 
    PrintedDoc WHERE EIN = :EIN");
    $statement->bindParam(":EIN", $EIN);
    $statement->execute();
    $EffectiveDateResults = $statement->fetchAll(PDO::FETCH_ASSOC);

    ?>
    <?php //BEGIN OUTPUT
    //BEGIN OUTPUT
    if ($DocumentListResult == false) {
        if 






 `enter code here`(file_exists("$ComplianceS3Bucket/Groups/Unsorted/".$EIN."/".$Year."/sit 
   emap.html")) {

        //NO ROWS FOR THIS EIN - REDIRECT TO SITEMAP ON S3
    ?>
        <iframe src="<?= 




    "$ComplianceS3BucketHTTPS/Groups/Unsorted/".$EIN."/".$Year."/sitemap.html" ?>" frameborder="0" width="700" height="700"></iframe><br>
<?php
        } elseif (file_exists("Groups/$EIN/$Year/sitemap.html")) {
            readfile("Groups/$EIN/$Year/sitemap.html");
        }
        elseif(isset($_SESSION['Agency']) && $_SESSION['Agency'] == 0){
?>
        Could not find documents, please <a href="/ComplianceDocumentGenerator/inputPage.php?EID=<?=$EIN?>"> Re-Print Documents </a><br><br>
<?php
        }
    } else {
        $selectedEffDate = "";
        ?>
<html>
    <head>Compliance Documents</head>
    <body>
        Below are Links to your Plan Documents. These Documents should be made available to your employees in paper or electronic format.
        Please consult the Department of Labor for details on the specific requirements about electronic document distribution.
        <ul>

            <?php foreach ($DocumentListResult as $document) { ?>
                <li><a href="<?=str_replace($ComplianceS3Bucket, $ComplianceS3BucketHTTPS, $document['FileLocation']).$document['FileName']?>"><?=$document['DisplayName'] ?></a></li>
            <?php

                $selectedEffDate = $document['EffectiveDate'];

                resort($document);

            }
    }   ?>
        </ul>

Я должен получить список форм из базы данных в алфавитном порядке. Я могу получить список форм, но он приходит в том порядке, в котором нет ни рифмы, ни причины. Мне либо нечего показать, либо просто одну форму, чтобы показать, либо она остается прежней.

1 Ответ

0 голосов
/ 14 октября 2019
 if (isset($Year)) {
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50), @effectiveYear 
    int
    set @ein = :EIN
    set @effectiveYear=:Year
    SELECT *
    FROM [Chamber].[dbo].[PrintedDoc]
  where ein = @ein and year(effectiveDate)=@effectiveYear and datetimePrinted `enter `enter code here`code here`= (select max(DateTimePrinted) from `PrintedComplianceDocuments p2 where p2.ein = @ein and `enter code 
  here`year(p2.effectiveDate)=@effectiveYear) order by displayName ASC");
    $statement->bindParam(":EIN", $EIN);
    $statement->bindParam(":Year", $Year);
} elseif (isset($EffectiveDate)) {
    # code...
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50), @effectiveDate 

    date
    set @ein = :EIN
    set @effectiveDate=:Date
    SELECT *
    FROM [Chamber].[dbo].[PrintedDoc]


    where ein = @ein and effectiveDate=@effectiveDate and datetimePrinted = `(select max(DateTimePrinted) from PrintedComplianceDocuments p2 where p2.ein 
    =@ein and p2.effectiveDate=@effectiveDate) order by displayName ASC");
        $statement->bindParam(":EIN", $EIN);


   $statement->bindParam(":Date", $EffectiveDate);
    } else {
    $server = getChamberMSSQL();
    $statement = $server->prepare("declare @ein varchar(50)
    set @ein = :EIN
   select * from Chamber.dbo.PrintedDoc p1
  where EIN = @EIN and DateTimePrinted = (select max(dateTimePrinted) from `PrintedeDoc p3 where p3.EIN = @EIN and p3.EffectiveDate = (select max(EffectiveDate) `enter code here`from Pri`ntedDoc p2 where p2.EIN = @ein)) order by displayName ASC");
    $statement->bindParam(":EIN", $EIN);
}
    $statement->execute();
    $DocumentListResult = $statement->fetchAll(PDO::FETCH_ASSOC);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...