-2

EDITED I have an sql query and I want to highlight the table row with a red highlight so that if the transaction_date = 0000-00-00 that whole row is highlighted with red. Here is the snippet of the code. The transaction_date shows the date that a specific training course was taken and if the course wasn't taken then the date that will be returned will be 0000-00-00. Any help would be greatly appreciated. Thank you.

  $sql = "SELECT DATE_FORMAT(date_fluids, '%m/%d/%Y ') AS transaction_date, first_name, last_name, supervisor_group, trade, t_id, c_id, department_number, date_fluids, fluids_refresh, fluid_period, employee_type
        FROM peopleinfo WHERE
        (last_name LIKE '%$value1%' )
        and 
        (trade LIKE '%$value2%')
        and
        (t_id LIKE '%$value3%')
        and
        (c_id LIKE '%$value4%')
        and
        (department_number LIKE '%$value5%')
        and
        (date_fluids LIKE '%$value6%')
        and
        (date_lock LIKE '%$value7%')
        and
        (date_confine LIKE '%$value8%')
        and
        (date_fall LIKE '%$value9%')
        and
        (supervisor_group LIKE '%$value10%')
        AND
        (employee_type='1')
        ORDER BY last_name ASC";






$query = mysqli_query($conn, $sql);

$row = (mysqli_fetch_array($query));    







if (!$query) {
    die ('SQL Error: ' . mysqli_error($conn));
}

while ($row = mysqli_fetch_array($query))
{

        if ($row['transaction_date'] == 0000-00-00){
    echo '<tr class="highlight">';
    echo         '<td >' . $row['first_name']. '</td>';
    echo         '<td >' . $row['last_name']. '</td>';
    echo         '<td >' . $row['supervisor_group']. '</td>';
   echo      '<td >' . $row['trade']. '</td>';
   echo      '<td >' . $row['t_id']. '</td>';
echo         '<td >' . $row['c_id']. '</td>';
   echo      '<td >' . $row['department_number']. '</td>';
    echo         '<td >' . $row['transaction_date']. '</td>';
    echo         '<td >'. $row['fluid_period']. '</td>';
echo '</tr>';
} else {
   echo '<tr >';
    echo         '<td >' . $row['first_name']. '</td>';
    echo         '<td >' . $row['last_name']. '</td>';
    echo         '<td >' . $row['supervisor_group']. '</td>';
   echo      '<td >' . $row['trade']. '</td>';
   echo      '<td >' . $row['t_id']. '</td>';
echo         '<td >' . $row['c_id']. '</td>';
   echo      '<td >' . $row['department_number']. '</td>';
    echo         '<td >' . $row['transaction_date']. '</td>';
    echo         '<td >'. $row['fluid_period']. '</td>';
echo '</tr>';

}  
}
mysqli_free_result($query);
mysqli_close($conn);
?>
 </tbody>
</table>
  • 2
    Where is your _attempt_ to do this? We need to see what you tried and what the result was to know where you're having trouble. – Patrick Q Feb 28 '19 at 16:41
  • Try it yourself Nick. Not that complicated. Add a condition and some css styling to your table row. – Zak Feb 28 '19 at 16:45
  • I shouldn't have to say it, but Prepare your Queries to prevent [SQLInjection](https://stackoverflow.com/questions/601300/what-is-sql-injection) `WHERE (last_name LIKE '%$value1%' )` – ArtisticPhoenix Feb 28 '19 at 16:48
  • @BaranselA. There's absolutely nothing wrong with using mysqli as long as you are using prepared statements and bound parameters. Simply using PDO instead of mysqli wouldn't magically remove OP's injection vulnerability. – Patrick Q Feb 28 '19 at 16:53
  • I did attempt this myself and I came up with using an if else statement that worked but it required me to change every other page instead of I believe only adding one line of code. It worked when I used an if else statement but I was thinking there may be an easier way inside of the sql query – Nick Ramon Feb 28 '19 at 16:59

1 Answers1

0

I would just do:

echo '<tr' . ($row['transaction_date'] === '0000-00-00' ? 'class="highlight"' : '') . '>

and then use css to highlight it however you want.

dave
  • 50,635
  • 4
  • 62
  • 77