Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/11/2006, 14:04
Kenetix
 
Fecha de Ingreso: mayo-2005
Mensajes: 8
Antigüedad: 19 años, 9 meses
Puntos: 0
Lo que quiero hacer es lo siguiente...
Tengo este codigo:
Código:
<?php
include ('mysql_connect.php');
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
$query2 = "SELECT $id, COUNT(id) FROM comments GROUP BY nid";
$result = @mysql_query($query);
$result2 = @mysql_query($query2);


if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$url = 'comments.php?id='.$row['id'];
echo '<p><b>'.$row['title'].'</b><br />
'.$row['sd'].'<br />
Posted by : <b>'.$row['author'].'</b><br />
'.$row['post'].'<br />
<a href="javascript:openComments(\''.$url.'\')"> Add new comment or view posted comments</a></p>';
}
} else {
echo 'There are no news posts to display';
}
$id = 1;
$query = "SELECT $id, COUNT(id) FROM comments GROUP BY nid";
$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

        $comments = $row['COUNT(id)'];
        echo "Add Comment ($comments)</br>";

        }
?>
Lo que quiero hacer esque para cada noticia en vez de <a href="javascript:openComments(\''.$url.'\')"> Add new comment or view posted comments</a></p>'; pueda poner "Add Comment (*)" y entre parentesis el numero de comentarios que hay... Los comentarios se muestran en cada noticia a traves de un pop-up dependiendo del newsid que tengan, lo que quiero hacer esque haya un contador de comentarios para cada noticia especifica.
Esta es la tabla de comentarios:
CREATE TABLE comments (
id INT(11) NOT NULL AUTO_INCREMENT,
nid INT(11) NOT NULL,
title VARCHAR(70) NOT NULL,
author VARCHAR(50) NOT NULL,
comment TEXT NOT NULL,
date DATETIME NOT NULL,
PRIMARY KEY (id)
);
nid: id de noticia