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

时间:2016-05-09 14:47:55

标签: php sql

我们的开发人员最近离开了,我能够用MS SQL查询拼凑一个PHP页面,该查询从我们的数据库中提取最近的提交并将其显示在表格中。我需要帮助尝试突出显示多次出现在结果中的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>

1 个答案:

答案 0 :(得分:1)

今天,我的心情非常好,所以现在我帮助你了。但请记住,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