wiggst3r Posted August 15, 2008 Share Posted August 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 15, 2008 Share Posted August 15, 2008 You would need to use mysql_num_rows() to count how many news stories are being returned. If it is 0, then don't display. If it is greater then 0, then display. Quote Link to comment Share on other sites More sharing options...
wiggst3r Posted August 15, 2008 Author Share Posted August 15, 2008 Any idea how I'd use that within my code? 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.