Jump to content

convert this code from asp to php (date related)


ramone_johnny
Go to solution Solved by lemmin,

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%>
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.