SQL/PHP query

Asked

Viewed 116 times

0

I am trying to make a query in the database in 2 tables and pull the data to page with a condition would be this if the id_noticia of one table equals the id of the other when clicking on the image or name will redirect to the news page according to the id however working would like a help if possible

<?php    

 $pagCorrente = 1;
 if(isset($_GET['pag'])){
     $pagCorrente = (int)$_GET['pag'];
 }
 $mostrar = 10;

 $pagCorrente = $pagCorrente * $mostrar - $mostrar;

 $sqlTotal = "SELECT count(id) as total FROM noticia0;";     
 $ex = $conexao->query($sqlTotal);  
 $total = mysqli_fetch_object($ex);  
 $total = $total->total;

 $quantPages = ceil($total / $mostrar);

 $sql = "    SELECT COUNT(*) FROM noticia0 n, noticia nn
     WHERE n.id_noticia = nn.id   
     ORDER BY n.id desc LIMIT $pagCorrente,$mostrar";
 $wx = $conexao->query($sql);

 while($linha = mysqli_fetch_object($wx)){

 ?>

<div class='div0'>
<a href="<?php echo SITE;?>noticia3.php?id=<?php echo $linha->id; ?>">
 <div class='pa'>
      <img src='<?php echo SITE . 'php/upload/' . $linha->imagen2;?>' />
  </div>

   <div class='po'>
   <p>
     <br><?php echo $linha->titulo;?></br>
     <br><?php echo $linha->sinopse;?></br>

1 answer

0

In your consultation, you are making a SELECT COUNT(*), is the only thing that is returning in its object, exchange for its alias n.*, nn.* that you will have the result of your query. If I have not understood very well, post which error is happening.

Abs.

  • I’ve already solved vlw man.

Browser other questions tagged

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