bradkenyon Posted May 29, 2008 Share Posted May 29, 2008 i have a news system, where you enter a news item into the form, you can check whether or not you want the news item to be a featured item, so if you check the box, it will store a 'Y' in the featureditem column of the table holding the news. i want to do display the most recent item that has the Y within the featureditem column. this is what i have so far, but the subject doesn't display ($row['subj']) when viewing the page. <? include('db.php'); $query = "SELECT * FROM news WHERE featureditem = 'Y' ORDER BY tstamp DESC"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { ?> <div class="alertitem"> <h3>News Flash!</h3> <? $row['subj']; ?> </div> <? } ?> what do you think i am doing wrong? any help is appreciated. thank you. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 29, 2008 Share Posted May 29, 2008 you forgot "print" <? include('db.php'); $query = "SELECT * FROM news WHERE featureditem = 'Y' ORDER BY tstamp DESC"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { ?> <div class="alertitem"> <h3>News Flash!</h3> <? print $row['subj']; ?> </div> <? } ?> Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted May 29, 2008 Author Share Posted May 29, 2008 oops. also, i need to fix the query to only look for the very first one, based on tstamp, and stop after it found it. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 29, 2008 Share Posted May 29, 2008 oops. also, i need to fix the query to only look for the very first one, based on tstamp, and stop after it found it. SELECT * FROM news WHERE featureditem = 'Y' ORDER BY tstamp DESC LIMIT 1; Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted May 30, 2008 Author Share Posted May 30, 2008 another question in reference to this. say i have the story marked as a feature. i dont want it to be up there as the featured story until a new one comes out, so i'd like to make an expiration, say it will expire 2 days after it was posted. i did something like this, but i am not sure if this will do the trick. <? include('db.php'); $query = "SELECT * FROM news WHERE featureditem = 'Y' ORDER BY tstamp DESC LIMIT 1"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { if($row['tstamp'] + 2 > date("Y-m-d H:i:s",time())) { ?> <div class="alertitem"> <h3>News Flash!</h3> <? print '<div class="content">'.$row['subj'].'</div>'; ?> </div> <? } else { print 'expired'; } } ?> 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.