How to make only things with status X displayed on the page?

0

I have a website, and in it some people can post things like news, and I'd like to make sure that only news that is approved (by team members) is shown, I already have the phpmyadmin system ready, the news has a new column called 'status' and to be activated should have status '1'. New news is created with status 0, but they appear the same on the page because there is no restriction, how could I add some sort of restriction to just such approved news being displayed? (Sorry for the lengthy or poorly explained text, it's my first time here on the site, I'm still learning)

* (Additional information: The Table where the news is called: news, it has some things mentioned here as: author, reviewed by and etc, and the column where it stays where it is activated is called status, 1 to enable 0 for not

Follow the 2 pages .php of the news section:

This page only has the base (nothing much, all the code of insertion of news is in the other, that only for you to have a base)

    <head>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-6295119959637671",
enable_page_level_ads: true
});
</script>
<head>
<div class="container">
    <div class="row">
        <div class="col-md-8">
                <div style="padding-top: 0px;" class="panel-body">
                    <div id="loader" style="text-aling:center;margin-left:50%;">
                        <img src="hk/loader.gif">
                    </div>
                    <div class="outer_div">
                    </div>
                    <!-- Datos ajax Final -->
                </div>
            </div>
        <div class="col-md-4">
<?php echo $redes_sociales; ?>
            <?php echo $cartel_publicidad; ?>
        </div>
    </div>
    <script>
    $(document).ready(function(){
        load(1);
    });
    function load(page){
        var parametros = {"action":"ajax","page":page};
        $("#loader").fadeIn('slow');
        $.ajax({
            url:'kernel/ajax/Body_Noticias_ajax.php',
            data: parametros,
             beforeSend: function(objeto){
            $("#loader").html("<img src='hk/loader.gif'>");
            },
            success:function(data){
                $(".outer_div").html(data).fadeIn('slow');
                $("#loader").html("");
            }
        })
    }
    </script>
</div>
<!-- /container -->

Complement of page where news is displayed: (this is another file)

<?php 
function paginate($reload, $page, $tpages, $adjacents) {
    $prevlabel = "&lsaquo; $lang[196]";
    $nextlabel = "$lang[197] &rsaquo;";
    $out = '<ul class="pagination pagination-large">';

    // previous label

    if($page==1) {
        $out.= "<li class='disabled'><span><a>$prevlabel</a></span></li>";
    } else if($page==2) {
        $out.= "<li><span><a href='javascript:void(0);' onclick='load(1)'>$prevlabel</a></span></li>";
    }else {
        $out.= "<li><span><a href='javascript:void(0);' onclick='load(".($page-1).")'>$prevlabel</a></span></li>";

    }

    // first label
    if($page>($adjacents+1)) {
        $out.= "<li><a href='javascript:void(0);' onclick='load(1)'>1</a></li>";
    }
    // interval
    if($page>($adjacents+2)) {
        $out.= "<li><a>...</a></li>";
    }

    // pages

    $pmin = ($page>$adjacents) ? ($page-$adjacents) : 1;
    $pmax = ($page<($tpages-$adjacents)) ? ($page+$adjacents) : $tpages;
    for($i=$pmin; $i<=$pmax; $i++) {
        if($i==$page) {
            $out.= "<li class='active'><a>$i</a></li>";
        }else if($i==1) {
            $out.= "<li><a href='javascript:void(0);' onclick='load(1)'>$i</a></li>";
        }else {
            $out.= "<li><a href='javascript:void(0);' onclick='load(".$i.")'>$i</a></li>";
        }
    }

    // interval

    if($page<($tpages-$adjacents-1)) {
        $out.= "<li><a>...</a></li>";
    }

    // last

    if($page<($tpages-$adjacents)) {
        $out.= "<li><a href='javascript:void(0);' onclick='load($tpages)'>$tpages</a></li>";
    }

    // next

    if($page<$tpages) {
        $out.= "<li><span><a href='javascript:void(0);' onclick='load(".($page+1).")'>$nextlabel</a></span></li>";
    }else {
        $out.= "<li class='disabled'><span><a>$nextlabel</a></span></li>";
    }

    $out.= "</ul>";
    return $out;
}
?>
<?php
    require ('../../global.php');

    $action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
    if($action == 'ajax'){
        //las variables de paginación
        $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
        $per_page = 6; //la cantidad de registros que desea mostrar
        $adjacents  = 4; //brecha entre páginas después de varios adyacentes
        $offset = ($page - 1) * $per_page;
        //Cuenta el número total de filas de la tabla*/
        $count_query   = $link->query("SELECT count(*) AS numrows FROM noticias ");
        if ($row= mysqli_fetch_array($count_query)){$numrows = $row['numrows'];}
        $total_pages = ceil($numrows/$per_page);
        $reload = 'furni.php';
        //consulta principal para recuperar los datos
        $query = $link->query("SELECT * FROM noticias  order by id DESC LIMIT $offset,$per_page");

        if ($numrows>0){
            while($row = mysqli_fetch_array($query)){
?>
<div style="background-image: url(<?php echo $row['imagen']; ?>);background-position: 50%;margin-bottom: 15px;border-radius: 5px" class="articulo">
    <a href="articulo.php?id=<?php echo $row['id']; ?>">
  <div class="contenedor-datos">
        <div class="contenedor-likes">
            <div style="float:left;font-size: 14px;"><i style="font-size: 11px;" class="material-icons">thumb_up</i> <?php echo $row['megusta']; ?></div>
            <div style="margin-left:10px;float:left;font-size: 14px;"><i style="font-size: 11px;" class="material-icons">thumb_down</i> <?php echo $row['no_megusta']; ?></div>
        </div>
        <p><span style="color: rgb(204, 204, 204);"><span class="datos-noticia"><?php echo $lang[34]; ?>: <?php echo "$row[fecha]"; ?> <span style="margin-left:15px;"><?php echo $lang[35]; ?>: <?php echo "$row[categoria]"; ?><span style="margin-left:15px;"><?php echo $lang[36]; ?>: <?php echo "$row[autor]"; ?><span style="margin-left:15px;"> <?php echo $lang[456]; ?>: <?php echo "$row[autorizado]"; ?> </span></span>
          </span>
            </span>
    </p></div>
    <div style="height: 55px;position: relative;padding: 10px;float: left;width: 55%;background-color: rgba(0, 0, 0, 0.86);overflow: hidden;">
        <div class="titlesmallarticulo">
            <a href="articulo.php?id=<?php echo $row['id']; ?>">
                <?php echo "$row[titulo]"; ?>           </a>
        </div>
        <div style="color:#ccc;" class="resumen-noticia">
            <?php echo "$row[resumen]"; ?>                <br>
        </div>

    </div>
<div class="detalle-titulo"></div>

    </a>
</div>
                <?php
            }
            ?>

        <div class="table-pagination pull-right">
            <?php echo paginate($reload, $page, $total_pages, $adjacents);?>
        </div>

            <?php

        } else {
            ?>
            <div class="alert alert-warning alert-dismissable">
              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
              <?php echo $lang[195]; ?>
            </div>
            <?php
        }
    }
?>

I think the codes have been too long, but I really need them, and I have no idea what to do. I'm new to .php; (

    
asked by anonymous 06.04.2018 / 03:18

1 answer

1

In:

SELECT * FROM noticias  order by id DESC LIMIT $offset,$per_page

Add a WHERE clause:

SELECT * FROM noticias WHERE status = 1 order by id DESC LIMIT $offset,$per_page

This will search the table and pay only those lines that have the satus column 1

Caution When using string interpolation to pass data to the SQL script you are subject to SQL Injection

    
06.04.2018 / 03:26