简体   繁体   English

PHP MSSQL 查询突出显示多封电子邮件

[英]PHP MSSQL Query highlight multiple emails

Our developer recently left, I was able to cobble together a PHP page with a MS SQL query that pulls recent submissions from our database and displays them in a table.我们的开发人员最近离开了,我能够将 PHP 页面与 MS SQL 查询拼凑在一起,该查询从我们的数据库中提取最近提交的内容并将它们显示在表格中。 I need help trying to highlight via css email addresses (E.Email) that appear in the results more than once.我需要帮助尝试通过多次出现在结果中的 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>

Today, I am in a very good mood, so now I help you.今天我心情很好,所以现在我来帮你。 But keep in mind, StackOverflow is not the place, where you will always get free code for your problems.但请记住,StackOverflow 不是您总能获得解决问题的免费代码的地方。 I suggest you to immedatly hire a new programmer, collect these kind of jobs and give it to a freelancer.我建议你立即雇用一个新程序员,收集这些工作并将其交给自由职业者。

You need something like this:你需要这样的东西:

//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