Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Q2A Core by

I had several situations where an anonymous poster could not find his content again (due to search or due to renamed question), and posted the question once again. So we have a duplicate :(

This is why I would like to list all his questions on top. Like:

"You posted: • x • y • z"

How would you implement that?


I'd try to:

1. qa_cookie_get() → cookieID

2. go into the DB and search all questions that belong to the cookieID

But is this save? Will it be handled correctly?

1 Answer

0 votes

Alright, I scripted a bit ;)

This seems to work:

    // get cookie of anonymous user
    $cookieid = qa_cookie_get();
    if(!is_null($cookieid) && (($this->template=='qa')||($this->template=='questions')) ) {
        // get questions of anonymous user within last 3 days
        $allQu = qa_db_read_all_assoc( qa_db_query_sub('SELECT postid FROM ^posts
                                                            WHERE cookieid = #
                                                            AND `type`="Q"
                                                            AND created > NOW() - INTERVAL 3 DAY
                                                        ', $cookieid) );
        $questionList = '<ul>';
        foreach($allQu as $quItem) {
            // get correct public URL
            $getQtitle = qa_db_read_one_assoc( qa_db_query_sub('SELECT title FROM `^posts` WHERE `postid` = # LIMIT 1', $quItem['postid']) );
            $qTitle = (isset($getQtitle['title'])) ? $getQtitle['title'] : '';
            $qLink = qa_path_html(qa_q_request($quItem['postid'], $qTitle), null, qa_opt('site_url'), null, null);
            $questionList .= '<li><a href="'.$qLink.'">'.htmlspecialchars($qTitle).'</a></li>';
        $questionList .= '</ul>';
        $this->output('<p style="">Hi guest, these are your recent questions:</p>'.$questionList.'<br />');


Maybe it helps you too =)