Status in the news system [closed]

0

I have a news system and it is derived from the status, if $ status = Active it appears and if $ status = Inactive it does not appear, how can I do this?

<?php
$news8 = mysql_query("SELECT * FROM 10cms_noticias ORDER BY ID DESC LIMIT 8") or die(mysql_error());
?>
<?php $i = 0; while($noticias = mysql_fetch_assoc($news8)){ $i++; ?>
            <div class='noticia'>
                <div class='img' style='background-image: url(<?php echo $noticias['img']; ?>);'></div>
                <div class='titulo'><b><?php echo $noticias['titulo']; ?></b></div>
                <div class='desc'><?php echo $noticias['resumo']; ?></div>
                <div class='info'>
                    <div class='comentarios' title="20 Comentários"></div>
                    <div class='data' title="<?php echo $noticias['data']; ?>"></div>
                    <div class='autor' title="<?php echo $noticias['autor']; ?>" </div>
                </div>
            </div>
        <?php } ?>
    
asked by anonymous 23.07.2015 / 22:01

2 answers

3

If the status is in the news table, use WHERE in SQL:

$news8 = mysql_query("SELECT * FROM 10cms_noticias WHERE status = 'ativo' ORDER BY ID DESC LIMIT 8") or die(mysql_error());
    
23.07.2015 / 22:11
3

You have not explained whether the $ status variable is from MySQL or PHP. If it's PHP:

<?php
$status = "ativo";
$news8 = mysql_query("SELECT * FROM 10cms_noticias ORDER BY ID DESC LIMIT 8") or die(mysql_error());
if($status == "ativo") {
?>
?php $i = 0; while($noticias = mysql_fetch_assoc($news8)){ $i++; ?>
        <div class='noticia'>
            <div class='img' style='background-image: url(<?php echo $noticias['img']; ?>);'></div>
            <div class='titulo'><b><?php echo $noticias['titulo']; ?></b></div>
            <div class='desc'><?php echo $noticias['resumo']; ?></div>
            <div class='info'>
                <div class='comentarios' title="20 Comentários"></div>
                <div class='data' title="<?php echo $noticias['data']; ?>"></div>
                <div class='autor' title="<?php echo $noticias['autor']; ?>" </div>
            </div>
        </div>
    <?php } } ?>

If it is not, follow the example of @Weslley Buback

    
24.07.2015 / 00:41