Select limiting query, and does not display the last queries

0

In this script, it is limited to displaying 6 queries in SELECT in the variable $ amount_pg = 6, I used the IF to inform that all news situations other than 2 (unpublished) should be displayed. Home The detail is that in my SELECT, in order of creation from the most recent to the oldest, the detail is that limiting 6 news, and is with the oldest date does not display these news. Example: I have a total of 10 news items, 1 per week, but the last 6 news items are displayed in the order of most recent to oldest, but by unpublishing 6 news items in the middle weeks, leaving the 2 most recent news and 2 latest news , should be displayed, but in this script it only displays the most recent 2 not displaying the oldest ones. It seems that the IF is limited to SELECT, and ends up understanding that it has 6 queries. I searched the net for limiting on the while or aldo type, or doing the INNER JOIN on the SELECT. Can anybody help me. I have this code:

        $pagina = (isset($_GET['pagina']))? $_GET['pagina'] : 1;
        //Selecionar os noticias a serem apresentado na página da mais recente a antiga
        $result_noticias = "SELECT * FROM noticias ORDER BY created DESC";

        //Selecionar os noticias a serem apresentado na página
        $resultado_noticias = mysqli_query($conn, $result_noticias);

        //Contar o total de noticias
        $total_noticias = mysqli_num_rows($resultado_noticias);

        //Seta a quantidade de noticias por pagina
        $quantidade_pg = 6;

        //calcular o número de pagina necessárias para apresentar os noticias
        $num_pagina = ceil($total_noticias/$quantidade_pg);

        //Calcular o inicio da visualizacao
        $incio = ($quantidade_pg*$pagina)-$quantidade_pg;

        //Selecionar os noticias a serem apresentado na página
        $result_noticias = "SELECT * FROM noticias ORDER BY created DESC limit $incio, $quantidade_pg";
        $resultado_noticias = mysqli_query($conn, $result_noticias);
        $total_noticias = mysqli_num_rows($resultado_noticias);
                <?php while($row_noticias = mysqli_fetch_assoc($resultado_noticias)){?>
                                                                          ">                                                                                                               
  •                                                           
  •                            

                              ...                                                                                

But in my bank I have the news table and the column situacao_noticia_id (id1 / id2) . I have the other table situacao_noticia , in it the columns (id / name) , so (id1 / published) - (id2 / unpublished)

I would like, when the ID is 2 (unpublished), do not display the news in the while.
There is a lack of knowledge on my part.

    
asked by anonymous 09.05.2017 / 21:18

1 answer

1

Try to put your entire article inside an if / else. In the if you check if the news id equals 2, if it is, just have it carry on, if not, have it execute the else block with the article inside.

    
09.05.2017 / 21:45