Jump to content

convert this code from asp to php (date related)


ramone_johnny

Recommended Posts

Hey guys,

Im wanting to have this bit of code rewritten into PHP.

 

It basically checks the date pulled from the DB and if its only 2 days old, it displays a "new listing" image.

<%share_newlisting = DateDiff("d", rstDBEdit("share_datecreated"), now())
			if share_newlisting < 2 then%>
            <div style="margin-top:5px"><img src="/images/new_listing.gif" width="81" height="15" align="absbottom"></div>
            <%end if%>

There is still not enough information to do this, but I can give you an idea:

mysql_connect($db, $user, $pass);	//Connect to db
mysql_select_db('yourdb');	//Select db
$r = mysql_query('SELECT * FROM yourtable');	//query for listings
while ($row = mysql_fetch_assoc($r))	//loop through listings
{
	$days = 2;	//set days
	$seconds = 60 * 60 * 24 * $days;	//calculate seconds in days
	if ((time()-$row['share_datecreated']) < $days)	//check stamp
		//New listing	
}

This assumes that your share_datecreated field is a timestamp and that you have no criteria for which listings to grab from the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.