PDA

View Full Version : question regarding MySQL and PHP


abcdefGARY
02-02-2008, 02:25 AM
Hello, I have a small question regarding MySQL and PHP... Now, I don't know much about these two languages so I am not really sure if this information is enough.

funtion getStoriesPopular($count = FALSE, $popular_count = 15, $num = NULL, $offset = NULL){
$limit = '';
if($num != NULL){
$limit = sprintf('LIMIT %1$d,%2$d', $offset, $num);
}

$sql = 'SELECT
posts.*,
fa_user.*,
(
SELECT count(DISTINCT parentid)
FROM comments
WHERE comments.postid = posts.postid
) AS unique_commenters
FROM posts
JOIN fa_user ON fa_user.id = posts.ownerid
WHERE commentcount > ?
ORDER BY posts.modifytime DESC, posts.posttime DESC
%s';
$sql = sprintf($sql, $limit);
$query = $this->db->query($sql, array($popular_count));

if($count == TRUE){
return $query->num_rows();
} else {
return $query->result();
}
}Basically, from the code above, it will grab "popular stories" from the DB that have a "commentcount" that is greater than ?

However, I want to modify the code so that it grabs "popular stories" from the DB that has "unique_commenters" that is greater than ?

I'm not sure if this is understandable, but I thought I might ask anyways.

Please let me know if there are any questions.

Thanks.

oesxyl
02-04-2008, 09:25 PM
I don't know if this could help but can you post table structure?

best regards