Jump to content

php mysql query, need to grab the most recent flagged item


bradkenyon

Recommended Posts

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.

 

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>
       <?
   }
       
?>

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';
	}
}

?>

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.