-1

I have table called reservations. It displays reservations made by users. I want highlight records in current date using end date.

Php code

$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");                         
while ($row = mysql_fetch_array($result2)) {

    echo '<tr>';
    echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
    echo '<td class="contacts">' . $row['start'] . '</td>';
    echo '<td class="contacts">' . $row['end'] . '</td>';
    echo '<td class="contacts">' . $row['qty'] . '</td>';

    echo '</td>';
    echo '<td class="contacts">' . $row['room_type'] . '</td>';
    echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
    echo '</tr>';
}
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
  • 1
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 19 '15 at 12:19
  • 1
    Ok, and have you tried anything? getting errors? you only told us you want to *highlight records in current date using end date.* – Funk Forty Niner May 19 '15 at 12:19
  • This has nothing to do with PHP or MySQL. If you want to add styling to specific rows, then add another CSS class and style that class to highlight the rows. – David May 19 '15 at 12:20
  • Yes I have no idea to do it – Achira silva May 19 '15 at 12:24
  • you have just check current date matches with sys date in your iteration part and highlight that using css or add one more highlighter class – nilesh suryavanshi May 19 '15 at 12:28

2 Answers2

0

I'd do that at frontend side, but if you want to compute than in PHP, you will need to compare the date from $row and current date and add a class or a style tag to the .

Like so:

$rowHasCurrentDate = $row['date'] == date('Y-m-d'); echo '<tr' + ($rowHasCurrentDate ? ' class="highlight-row"' : "") + '>';

instead of

echo '<tr>';

You can replace the 'class="highlight-row"' with 'style="background-color:red"' if you want to do it without touching frontend side at all.

The example is kinda spaghetti-code, but you can move this logic somewhere else after you get it working.

Kremnev Sergey
  • 332
  • 1
  • 8
0

I am assuming that your start date is current date. This is css thing, i have given you solution to you.

<html>

<head>
<style>
.currdate
{
    background-color:red; //change this color to whatever you wish to change to 
}
</style>
</head>
<body>
<?php
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");                         
while ($row = mysql_fetch_array($result2)) {

    echo '<tr>';
    echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
    echo '<td class="contacts currdate">' . $row['start'] . '</td>';
    echo '<td class="contacts">' . $row['end'] . '</td>';
    echo '<td class="contacts">' . $row['qty'] . '</td>';

    echo '</td>';
    echo '<td class="contacts">' . $row['room_type'] . '</td>';
    echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
    echo '</tr>';
}
?>
<body>

</html>
Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33