Status in the news system

Asked

Viewed 101 times

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 } ?>
  • if(status=ativo) {//seu ódigo} else {//menssagem de erro ou assim}

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());

3

You have not explained whether the $status variable is coming from Mysql or PHP. If it is from 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 not, follow @Weslley Buback’s example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.