Pulling information from a table to a news page

Asked

Viewed 64 times

1

I have a news page that pulls id (is one of those noticias.php?id=1), but I wanted her to tell only the news comments I’m reading, not all. That’s possible?

I already got PHP to count, but I wanted to give this specified.

PHP to tell:

 <?php
 $contador = mysql_query("SELECT count(id) as total FROM 10cms_noticias_resp 
                         WHERE id_noticia = id_noticia") or die(mysql_error());

$comentario = mysql_fetch_assoc($contador);
 ?>
 <?php echo $comentario['total'];

  ?>

PHP of my page:

    $id = $_GET['id']; 
 $noticiass = mysql_query("SELECT * FROM 10cms_noticias WHERE id = $id") or die(mysql_error()); ?> 
 <?php $i = 0; while($edit = mysql_fetch_assoc($noticiass)){ $i++; ?>
  • What’s the problem @Kloves?

  • is because it counts all the comments, not only the news that I’m reading.

1 answer

4


$contador = mysql_query("SELECT count(id) as total FROM 10cms_noticias_resp 
                     WHERE id_noticia = id_noticia") or die(mysql_error());

That first clause WHERE is wrong. The id_noticia will always be like himself.
You have to pass a value (or variable) that corresponds to the id of the news you want to consult.

  • 1

    WOW! I got it, thank you very much.

Browser other questions tagged

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