$queryDuplicates = qa_db_query_sub('SELECT postid,closedbyid,title,userid,created
FROM `^posts`
WHERE `type` = "Q"
AND `closedbyid` IS NOT NULL
ORDER BY created ASC
;');
// initiate output string
$duplicatesList = "<table> <thead><tr> <th style='text-align:center'>Date</th> <th>Question Title</th> <th>User</th> <th>Answers</th> <th>Comments</th> </tr></thead>";
$dupCount = 0;
while ( ($duprow = qa_db_read_one_assoc($queryDuplicates,true)) !== null ) {
// query recent user
$currentUser = $duprow['userid'];
$userrow = qa_db_select_with_pending( qa_db_user_account_selectspec($currentUser, true) );
// check closed-by to see if just-closed (type=NOTE) or if its duplicate-closed (type=Q)
$closedByQu = qa_db_read_one_value( qa_db_query_sub('SELECT postid FROM `^posts`
WHERE `postid` = #
AND `type` = "Q"
;', $duprow['closedbyid']), true );
if(isset($closedByQu)) {
$dupCount++;
// get number of answers to recent question
$nAnswers = qa_db_read_one_value( qa_db_query_sub('SELECT COUNT(*) FROM `^posts`
WHERE `parentid` = #
AND `type` = "A"
;', $duprow['postid']), true );
// get number of comments to recent question
$nComments = qa_db_read_one_value( qa_db_query_sub('SELECT COUNT(*) FROM `^posts`
WHERE `parentid` = #
AND `type` = "C"
;', $duprow['postid']), true );
$duplicatesList .= '<tr> <td>'.substr($duprow['created'],0,10).'</td> <td><a href="'.qa_path_html(qa_q_request($duprow['postid'], $duprow['title']), null, qa_opt('site_url'), null, null).'">'.$duprow['title'].'</a></td> <td>'. qa_get_one_user_html($userrow['handle'], false) .'</td> <td>'.$nAnswers.'</td> <td>'.$nComments.'</td> </tr>';
}
}
$duplicatesList .= "</table>";