Jump to content

hiding News Archive


wiggst3r

Recommended Posts

Hi

 

I have a news page, which lists the news items in the database on a page.

 

I have an admin page, which I can add a news story, and make it 'Active' or 'Archived'

 

As I don't have any arcvhived news stories yet, I want it to hide the <h4></h4> that is displayed and then below that is the 'Archived News'

 

My code so far is:

 

<?php
			$stories = get_news_stories();
			global $db;
			while($one_row = $db->db_fetch($stories))
			{
				?>
				<h4><?=$one_row['title']?></h4>
				<div style="float: right; margin-top: -20px; color: #000000; font-size: 14px;	"><? echo  date("d-m-Y",strtotime($one_row['date']))  ?></div>
				<p class="news" ><?=$one_row['description']?></p>


				<?php
			}
			?>

			<h4 class="header">News Archive</h4>
			<?php
			$stories = get_news_stories_archived();
			global $db;
			while($one_row = $db->db_fetch($stories))
			{
				?>
				<table border="0" width="650" style="margin-left: 7px;" class="archive">
				<tr>
				<td class="archive"><a href="news-archive.php?id=<?=$one_row['id']?>" style="text-align: center; "><? echo substr($one_row['title'],0,60) . '..';   ?></a></td>
				<td width="100" style="text-align: right; font-size: 12px; color: #fffff;	"><? echo  date("d-m-Y",strtotime($one_row['date']))  ?></td>
				</tr>
				</table>
				<div style="border-bottom: 1px solid #666; margin-top: 8px; margin-left: 5px;"></div>
				<?php
			}
			?>

 

you can see there is the <h4> for the Archived News. So far, this is always displayed, but I want it to display only when there is a story that has been flagged as 'Archived'

 

2 functions:

 

get_news_stories_archived()

 

function get_news_stories_archived($include_archived = true)
{
global $db;
$include_archived?$sql_where="status != 0 and status != 1":$sql_where="status = 2";
$sql = " SELECT * FROM news WHERE $sql_where ORDER BY sort_order ASC ";
$result = $db->db_query($sql);
return $result;
}

 

function get_news_stories($include_archived = false)
{
global $db;
$include_archived?$sql_where="status != 0":$sql_where="status = 1";
$sql = " SELECT * FROM news WHERE $sql_where ORDER BY sort_order ASC ";
$result = $db->db_query($sql);
return $result;
}

 

How will I achieve what I'm looking to do with the code I've supplied?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/119837-hiding-news-archive/
Share on other sites

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.