ramone_johnny Posted April 11, 2013 Share Posted April 11, 2013 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%> Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 11, 2013 Share Posted April 11, 2013 More information is needed to do this. What type of database are you using and how is it structured? Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 11, 2013 Author Share Posted April 11, 2013 Sorry, its a mysql database. rstDBEdit("share_datecreated") is a date field. Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 11, 2013 Author Share Posted April 11, 2013 I tried this as a test, but obviously, it's not right. if(strtotime($rstDBEdit["share_datecreated"])<strtotime('-7 days')){ echo "this is a new ad"; Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 11, 2013 Author Share Posted April 11, 2013 What about this? $timestamp = strtotime($rstDBEdit["share_datecreated"]);$oneweekago = strtotime("-1 week");if($oneweekago<=$timestamp) {echo "this is a new ad";} ...can this be written better? Quote Link to comment Share on other sites More sharing options...
Solution lemmin Posted April 11, 2013 Solution Share Posted April 11, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.