Gene87 Posted December 25, 2017 Share Posted December 25, 2017 I need to know how to set ad listings to expire 30 days in php mysql?i know i have to ad some kind of feids in the myql table of listingshere is my php code to the page where it displays the for sale listings and catagories </> <div class="orageBGfg" style="padding:2px 0px 2px 20px;"> <b>Category</b> : <? echo "$category";?> <? $query = "SELECT COUNT(*) FROM forsale_content WHERE category='$category' AND status='online'"; $numentries = mysql_query($query) or die("Select Failed!"); $numentry = mysql_fetch_array($numentries); ?> </div> <b class="orageBG"> <b class="orageBG5"></b> <b class="orageBG4"></b> <b class="orageBG3"></b> <b class="orageBG2"><b></b></b> <b class="orageBG1"><b></b></b></b> </div> <div id="title1"> Click on title to view description </div> <? $sql = "SELECT * FROM forsale_content WHERE category='$category' AND status='online' ORDER BY id DESC"; $result = mysql_query($sql); while ($record = mysql_fetch_object($result)) { $question = nl2br($record->description); $answer = nl2br($record->answer); ?> <div id="list"> <a href="?q=detail&id=<? echo"$record->id";?>"><? echo "$record->title"; ?><?php if($record->price != "") { ?> - $<? echo number_format($record->price);?> <?php } ?></a> <span>(<? echo "$record->city"; ?>) (<? echo "$record->postdate";?>)</span> </div> <? } ?></> here is the mysql table for the listing content </>CREATE TABLE IF NOT EXISTS `forsale_content` ( `id` int(11) NOT NULL AUTO_INCREMENT, `postdate` date DEFAULT NULL, `posttime` varchar(10) DEFAULT NULL, `name` varchar(250) DEFAULT NULL, `phone` varchar(250) DEFAULT NULL, `address` varchar(250) DEFAULT NULL, `city` varchar(255) DEFAULT NULL, `country` varchar(250) DEFAULT NULL, `email` varchar(250) DEFAULT NULL, `website` varchar(250) DEFAULT NULL, `title` varchar(250) DEFAULT NULL, `price` varchar(250) DEFAULT NULL, `description` text, `category` varchar(250) DEFAULT NULL, `photo` varchar(250) DEFAULT NULL, `status` varchar(250) DEFAULT NULL, `password` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=46 ;</> any help how to make this script s listing exprie after 30 or 60 or 90 days would be great thanks sorry for the bad code had to updat some of it to work with php 5.3 and up Quote Link to comment https://forums.phpfreaks.com/topic/305975-need-to-know-how-to-set-ad-listings-to-expire-30-days-in-php-mysql-php/ Share on other sites More sharing options...
requinix Posted December 25, 2017 Share Posted December 25, 2017 Store an expiration date and only show ads that haven't expired yet. For existing ads you can update the table using UPDATE forsale_content SET thenameofthenewcolumn = postdate + INTERVAL ?? DAYObviously change thenameofthenewcolumn and ?? as needed. It's definitely possible to not add the column and enforce 30/60/90 days on all ads - easily, in fact - but using the column gives you more flexibility. Quote Link to comment https://forums.phpfreaks.com/topic/305975-need-to-know-how-to-set-ad-listings-to-expire-30-days-in-php-mysql-php/#findComment-1554863 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.