簡體   English   中英

PHP MSSQL 查詢突出顯示多封電子郵件

[英]PHP MSSQL Query highlight multiple emails

我們的開發人員最近離開了,我能夠將 PHP 頁面與 MS SQL 查詢拼湊在一起,該查詢從我們的數據庫中提取最近提交的內容並將它們顯示在表格中。 我需要幫助嘗試通過多次出現在結果中的 css 電子郵件地址 (E.Email) 突出顯示。

// Select queries
$query = mssql_query("

SELECT 
E.EntryID,
E.FirstName,
E.MiddleInitial,
E.LastName,
E.Address,
E.City,
E.Region,
E.Postalcode,
E.Country,
E.DaytimePhone,
E.EveningPhone,
E.FaxNumber,
E.Email,
E.AuthorizedPerson,
E.SubmitterType,
E.Amount,
E.PaymentMethod,
E.Company,
E.CompleteDate,
CAST (S.Category as TEXT) as SubCat,
CAST (S.Title as TEXT) as SubmissionTitle,
CAST (S.CopyrightOwner as TEXT) as SubCopyOwner,
S.CopyrightYear,
S.Donate,
S.FastFrame,
S.DeclaredValue,
CAST (S.IntendePurpose as TEXT) as SubPurpose,
CAST (C.FirstName as TEXT) as Contributors_FirstName,
CAST (C.LastName as TEXT) as Contributors_LastName,
CAST (C.Email as TEXT) as Contributors_Email,
C.IsMember

FROM

Entries E LEFT JOIN Submissions S ON E.EntryID = S.EntryID
LEFT JOIN Contributors C ON C.SubmissionID = S.SubmissionID
WHERE E.CompleteDate > CONVERT(datetime, '2016-04-10T07:08:22',  126)
ORDER BY E.CompleteDate DESC
");



// display the results!
if (!mssql_num_rows($query)) {
    echo 'No records found';
} else {
    ?>
    <button id="export" data-export="export">Export</button>
    <br><br>
    <table id="ReportTable">
        <thead>
            <tr>
                <th>EntryID</th>
                <th>Completed Date</th>
                <th>First Name</th>
                <th>Middle Initial</th>
                <th>Last Name</th>
                <th>Address</th>
                <th>City</th>
                <th>Region</th>
                <th>Postal Code</th>
                <th>Country</th>
                <th>Day Phone</th>
                <th>Night Phone</th>
                <th>Fax #</th>
                <th>Email</th>
                <th>Authorized Person</th>
                <th>Submitter Type</th>
                <th>Amount</th>
                <th>Pay Method</th>
                <th>Company</th>
                <th>Submission Category</th>
                <th>Submission Title</th>
                <th>Submission Copyright Owner</th>
                <th>Submission Copyright Year</th>
                <th>Vesalius Trust</th>
                <th>FastFrame Discussion</th>
                <th>Declared Value</th>
                <th>Submission Purpose</th>
                <th>Contributor First Name</th>
                <th>Contributor Last Name</th>
                <th>Contributor Email</th>
                <th>Contributor Is Member</th>
            </tr>
        </thead>
        <tbody>
        <?php 
            while ($row = mssql_fetch_array($query)) {
                echo'<tr>'; 
                echo'<td>'. $row['EntryID'].'</td>';
                echo'<td>'. $row['CompleteDate'].'</td>';
                echo'<td>'. $row['FirstName'].'</td>';
                echo'<td>'. $row['MiddleInitial'].'</td>';
                echo'<td>'. $row['LastName'].'</td>';
                echo'<td>'. $row['Address'].'</td>';
                echo'<td>'. $row['City'].'</td>';
                echo'<td>'. $row['Region'].'</td>';
                echo'<td>'. $row['PostalCode'].'</td>';
                echo'<td>'. $row['Country'].'</td>';
                echo'<td>'. $row['DayTimePhone'].'</td>';
                echo'<td>'. $row['EveningPhone'].'</td>';
                echo'<td>'. $row['FaxNumber'].'</td>';
                echo'<td>'. $row['Email'].'</td>';
                echo'<td>'. $row['AuthorizedPerson'].'</td>';
                echo'<td>'. $row['SubmitterType'].'</td>';
                echo'<td>'. $row['Amount'].'</td>';
                echo'<td>'. $row['PaymentMethod'].'</td>';
                echo'<td>'. $row['Company'].'</td>';
                echo'<td>'. $row['SubCat'].'</td>';
                echo'<td>'. $row['SubmissionTitle'].'</td>';
                echo'<td>'. $row['SubCopyOwner'].'</td>';
                echo'<td>'. $row['CopyrightYear'].'</td>';
                echo'<td>'. $row['Donate'].'</td>';
                echo'<td>'. $row['FastFrame'].'</td>';
                echo'<td>'. $row['DeclaredValue'].'</td>';
                echo'<td>'. $row['SubPurpose'].'</td>';
                echo'<td>'. $row['Contributors_FirstName'].'</td>';
                echo'<td>'. $row['Contributors_LastName'].'</td>';
                echo'<td>'. $row['Contributors_Email'].'</td>';
                echo'<td>'. $row['IsMember'].'</td>';
                echo'<tr>';
            }
        ?>
        </tbody>
    </table>

今天我心情很好,所以現在我來幫你。 但請記住,StackOverflow 不是您總能獲得解決問題的免費代碼的地方。 我建議你立即雇用一個新程序員,收集這些工作並將其交給自由職業者。

你需要這樣的東西:

//create a new empty array
$emailsExists= [];
while ($row = mssql_fetch_array($query)) {
    //here comes the cell of tables
    //...
    //...
    //when email comes:
    echo'<td>'. $row['FaxNumber'].'</td>';
    //if this email was already in the array
    if (in_array($row['Email'], $emailsExists)) {
        echo'<td><span style="color: red">'. $row['Email'].'</span></td>';
    } else {
        echo'<td>'. $row['Email'].'</td>';
        //Put this email into the existsing emails array
        $emailsExists[] = $row['Email'];
    }
    echo'<td>'. $row['AuthorizedPerson'].'</td>';
    //...
    //...
} //end of while

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM