简体   繁体   中英

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. I need help trying to highlight via css email addresses (E.Email) that appear in the results more than once.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM