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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

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.