Forum Moderators: coopster
Trying to add the words NEW! to a newly added article if the current date is a match to the articles date. Here is what I have:
$new_date_format = date("n/j/y",strtotime($row['web_date']));
$currentdate = date("n/j/y");
if ($web_date == $currentdate)
{
$new = "NEW!";
}
else
{
$new = "";
}
How can I display the word NEW! ? I am using the following code to "try" to display it:
echo "Date Added: ".$new_date_format."".$new."<br />";
if ($web_date == $currentdate)
{
$new = "NEW!";
echo "If statement is true!";
}
else
{
$new = "";
echo "If statement is false!";
}
If this works then if statement is working which then the error is with the last echo line.
which then try this.
echo "Date Added: " . $new_date_format . "" . $new . "<br />";
You should do your sql query like this:
$result = mysql_query("SELECT * FROM database and etc")
while($row = mysql_fetch_array($result))
{
$web_date = $row['web_date'];
}
EDIT:
Btw also change $new_date_format = date("n/j/y",strtotime($row['web_date']));
to
$new_date_format = date("n/j/y",strtotime($web_date));
Changed code, because of previous error, this makes more sense, but still not working.
Entire Code so far is:
$result = mysql_query("SELECT * FROM websites ORDER BY web_date DESC LIMIT $offset, $records_per_page ") or die(mysql_error());
if($row = mysql_fetch_array($result)) {
do{
$num = $row['rating_name'];
//START DATE CODE
$currentdate = date("n/j/y");
$stored_date = $row['web_date'];
if ($stored_date == $currentdate)
{
$new = " NEW!";
}
else
{
$new = "";
}
//END DATE CODE
$new_date_format = date("n/j/y",strtotime($row['web_date']));
echo "<div id=\"left_column_website\" class=\"row_hover\">";
echo "<div id=\"website_image\" class=\"galleryimage\">";
echo "<a target=\"_blank\" href=\"".$row['web_url']."\"><img src=\"".$row['web_image']."\" width=\"150\" height=\"65\" /></a></div>";
echo "<div id=\"website_info\"><span class=\"website_class\"><a target=\"_blank\" href=\"".$row['web_url']."\">".$row['web_name']."</a></span> - ".$row['web_desc']."<br />";
echo "<hr id=\"hr\" />";
echo "Date Added: " . $new_date_format . $new . "<br />";
echo "Website Type: ".$row['web_type']."<br />";
echo rating_bar($num,'5');
echo "</div>";
echo "</div>";
}
while($row = mysql_fetch_array($result));
}
?>
//START DATE CODE
$stored_date = $row['web_date'];
}
$currentdate = date("n/j/y");
if ($stored_date == $currentdate)
{
$new = " NEW!";
}
else
{
$new = "";
}
//END DATE CODE
$new_date_format = date("n/j/y",strtotime($row['web_date']));
echo "<div id=\"left_column_website\" class=\"row_hover\">";
echo "<div id=\"website_image\" class=\"galleryimage\">";
echo "<a target=\"_blank\" href=\"".$row['web_url']."\"><img src=\"".$row['web_image']."\" width=\"150\" height=\"65\" /></a></div>";
echo "<div id=\"website_info\"><span class=\"website_class\"><a target=\"_blank\" href=\"".$row['web_url']."\">".$row['web_name']."</a></span> - ".$row['web_desc']."<br />";
echo "<hr id=\"hr\" />";
echo "Date Added: " . $new_date_format . $new . "<br />";
echo "Website Type: ".$row['web_type']."<br />";
echo rating_bar($num,'5');
echo "</div>";
echo "</div>";
?>
Try this.
Tried the echo method again, heres what I got:
Stored Date 2009-08-03 Current Date 8/4/09
Seems Stored Date is a day behind, and just needs formatting to work.
EDIT:
Was able to do:
$stored_date = $row['web_date'];
$fixed_stored_date = date("n/j/y",strtotime($stored_date));
Now I am getting:
Stored Date 2009-08-03
Current Date 8/4/09
Fixed Stored Date 8/3/09
How can I add a day?