Forum Moderators: coopster

Message Too Old, No Replies

Probably Stupid Question.

         

Phillips126

12:31 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Hey guys...

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 />";

messageboy

12:43 am on Aug 5, 2009 (gmt 0)

10+ Year Member



echo "Date Added: " . $new_date_format . $new . "<br />";

Try that.

Phillips126

12:46 am on Aug 5, 2009 (gmt 0)

10+ Year Member



No such luck... Any other ideas?

I feel like this should be really easy...

messageboy

12:50 am on Aug 5, 2009 (gmt 0)

10+ Year Member



You should do a simple echo in parts of your coding to make sure that those fragments are working.

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 />";

Phillips126

12:57 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Grand Idea... and possibly points its finger to the true problem.

For EVERY article, including the ones that should say NEW!
It stated "If statement is false" at the top.

Guess that means the IF statement isn't working.

Any idea why?

BTW - Thanks for the fast replies!

messageboy

1:00 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Indeed it seems that the $web_date is not equal to $currentdate so you have to echo $web_date and echo $currentdate which will show you which one is at fault.

echo "Web date = " . $web_date . " Current date = " . $currentdate;

Phillips126

1:04 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Here is what I got:

Web date = Current date = 8/4/09

Reason being is because I am using a mySQL database to hold web_date for each article. To display web_date I have been using:

$row['web_date']

Should my code read...?

if ($row['web_date'] == $currentdate)

messageboy

1:07 am on Aug 5, 2009 (gmt 0)

10+ Year Member



It seems that $web_date doesn't have any content.

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));

Phillips126

1:20 am on Aug 5, 2009 (gmt 0)

10+ Year Member



EDIT:

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));
}
?>

messageboy

1:40 am on Aug 5, 2009 (gmt 0)

10+ Year Member



$result = mysql_query("SELECT * FROM websites ORDER BY web_date DESC LIMIT $offset, $records_per_page ") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$num = $row['rating_name'];

//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.

Phillips126

1:45 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Found out something else interesting...

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?

messageboy

1:55 am on Aug 5, 2009 (gmt 0)

10+ Year Member



strtotime("+1 day")

Phillips126

2:02 am on Aug 5, 2009 (gmt 0)

10+ Year Member



Got it working mate!

Thanks so much for both the solution and the response time, couldn't have done it without you!

messageboy

2:03 am on Aug 5, 2009 (gmt 0)

10+ Year Member



No problem everyone has their troubles.