Solved

<?php if (date == $row) echo ..... ?>

Posted on 2008-10-09
4
1,026 Views
Last Modified: 2012-06-21
Trying to get my system to display an image in the table if the returned $row date is over the last 24 hours. I've tried different methods and Google'd a few ideas, none have seemed to work so far.

Here is what I have so far:

<?php
$now = strtotime("now");
$lastdaystr = strtotime("+1 day", $now);
$dbdate1 = strtotime($row['CreationDateTime']);
$dbdate2 = strtotime($row2['LatestModification']);
?>

<?php if ($dbdate1 == $lastdaystr) { echo '<img src="img/new.gif" />'; } ?>
<?php if ($dbdate2 == $lastdaystr) { echo '<img src="img/new.gif" />'; } ?>

Knowing me I am probably barking up the wrong tree completely. Any ideas all?
0
Comment
Question by:BenthamLtd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
rgoble earned 500 total points
ID: 22678078
The first thing I noticed is that this is giving you tomorrows date, not yesterdays.
$lastdaystr = strtotime("+1 day", $now);

The second thing is that you are comparing the dates to see if they are equal, which depending on if they include times they may never be equal.

Try this instead.
<?php
$now = strtotime("now");
$lastdaystr = strtotime("-1 day", $now);
$dbdate1 = strtotime($row['CreationDateTime']);
$dbdate2 = strtotime($row2['LatestModification']);
?>
 
<?php 
  if ($dbdate1 >= $lastdaystr) 
  { 
     echo '<img src="img/new.gif" />'; 
  }
?>
<?php 
  if ($dbdate2 >= $lastdaystr) 
  { 
     echo '<img src="img/new.gif" />'; 
  }
?>

Open in new window

0
 

Author Comment

by:BenthamLtd
ID: 22678166
Wow thank you for the quick response and for pointing me in the right direction. Unfortunately though, it doesn't seem to work. Even if I update a "sheet" on my system, despite reading off today's date, it still won't display the "new.gif" image. I've attached the whole code of the table below, it might help a bit more.

Thank you again and in advance.
<div id="history_table">
<?php
$now = strtotime("now");
$lastdaystr = strtotime("-1 day", $now);
$dbdate1 = strtotime($row['CreationDateTime']);
$dbdate2 = strtotime($row2['LatestModification']);
?>
 
 
<table width="400" class="history">
<tr>
	<td colspan="4" class="hed">Sheet History </td>
</tr>
<tr>
	<td colspan="4">&nbsp; </td>
</tr>
<tr>	
	<td width="10"><?php if ($dbdate1 >= $lastdaystr) { echo '<img src="img/new.gif" />'; } ?> </td>
	<td width="83"><?php echo $row['CreationDateTime']; ?> </td>
	<td width="124"><?php echo $row['LoggedBy']; ?></td>
	<td width="177">created </td>
<?php do { ?>
<tr>
	<td><?php if ($dbdate2 >= $lastdaystr) { echo '<img src="img/new.gif" />'; } ?></td>
	<td><?php echo $row2['LatestModification']; ?> </td>
	<td><?php echo $row2['Name']; ?> </td>
	<td> modified </td>
<?php } while ($row2 = mysql_fetch_assoc($sql2));
					$rows = mysql_num_rows($sql2);
					if($rows > 0) {
						mysql_data_seek($sql, 0);
							$row2 = mysql_fetch_assoc($sql2);
					}
			?>
 
 
</table>
</div>

Open in new window

0
 
LVL 1

Expert Comment

by:rgoble
ID: 22678363
Sorry I missed it before, change this line

$lastdaystr = strtotime("-1 day", $now);

to

$lastdaystr = strtotime("-1 day");
0
 

Author Comment

by:BenthamLtd
ID: 22678502
Thank you ever so much for your help Rgoble. It works great! Although I had to slightly modify it. Don't ask why. You know what PHP is like ;)


// CreationDateTime
 
<?php if (strtotime($row['CreationDateTime']) >= strtotime("-1 day")) { echo '<img src="img/new.gif" />'; } ?>
 
// LatestModification (looped)
 
<?php if (strtotime($row2['LatestModification']) >= strtotime("-1 day")) { echo '<img src="img/new.gif" />'; } ?>

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Use Select Query to Return Results as a Form 9 42
PHP mail() function not working... 8 34
PHP function parameters defined 14 41
Special characters in a TCPDF 4 27
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question