0
I have a website, and in it some people can post things as if they were news, and I would like to make sure that only news that was approved (by members of the team) were shown, I already have the phpmyadmin system ready, the news has a new column called 'status' and to be activated must have the status "1". New news is created with status 0, but they appear the same way on the page because there is no restriction, how could I add some kind of restriction for only such approved news to be displayed? (I’m sorry if the text was extended or poorly explained, it’s my first time here on the site, I’m still learning)
*(Additional information: The table where the news is located is called: news, it has some things mentioned here as: author, revised by and etc, and the column where it is or is not activated is called status, 1 for activated 0 for not
Follow the 2 pages . php of the news section:
Page where only has the basis (nothing much, all the news insertion code is in the other, this just for you to have a basis)
<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 the page where the news is shown: (this is another file)
<?php
function paginate($reload, $page, $tpages, $adjacents) {
$prevlabel = "‹ $lang[196]";
$nextlabel = "$lang[197] ›";
$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">×</button>
<?php echo $lang[195]; ?>
</div>
<?php
}
}
?>
I think the code is too long, but I really need it, and I have no idea what to do. php ;(
NOTE: If I use the SQL command in the database: SELECT * FROM noticias WHERE status = 1 only news with status 1 appear in the records, then it is not an error in the database.
– N3tt0h
Opa Gui! Thanks! I believe there was a small bug in the cache and the news was not disappearing! But I cleaned and did as you said! And it worked! Thank you ♥
– N3tt0h