php - Highlighting row with same date AND almost same time

833

I have a mysql table with four colums:

date, time, ip, user

When loading the results I get something like this:

03-21 17:10:33 123.456.789.101 TestUser
03-21 17:12:31 123.456.789.101 TestUser
03-25 17:16:33 123.456.789.101 TestUser

I want to highlight (give a diff. text color) the rows with the same date AND time if within a 2min range, like the first two rows in my example.

How to do that?

1

Answer

Solution:

I would recommend dropping the date column in you database, and changing the TIME to a full TIMESTAMP, then using the MySQL timediff function to determine the difference between the two.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timediff

Once you have determined the time difference between the two, as you are echoing out the results add some inline css style or a different class to change the text color or background colour based on that difference.

Without seeing your code, I can do little to help though.

22

Answer

Solution:

You could use de strtotime function in PHP that converts a string into a date. Using some css styling is posible to highlight the results. For example:

$t1 = strtotime('03-21 17:10:33');
$t2 = strtotime ('03-21 17:12:31');
if( abs($t1-$t2) <= 120|| ){ //120 is the number of secons in 2 minutes
}

People are also looking for solutions to the problem: php - Joomla 3.4.1 Installation stuck at step 1

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.