Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Help for counting favorite questions per user.

0 votes
asked Jun 3, 2016 in Q2A Core by Frodo
I am trying the last 4 hours !!!! to display the number of favorite questions of each user in my advanced theme. i am using the code below:

$userfaved = qa_db_select_with_pending(qa_db_user_points_selectspec($handle));

$this->output(''.$userfaved['favorites'].' '.qa_lang_html('main/my_favorites').'');

but it doesnt work as it returns Undefined "favorites"... What i am doing wrong here ???? I am using similar code to get the number of questions a user asked and it works pretty fine !
Q2A version: 1.6.x
commented Jun 6, 2016 by Frodo
@donshakespeare thank you for responding and waiting for your answer ;)
commented Jun 8, 2016 by Frodo
moved Jun 8, 2016 by Frodo
What is the SQL query that returns the number of favorites a user has already favorited ???

1 Answer

+3 votes
answered Jun 8, 2016 by donshakespeare
selected Jun 8, 2016 by Frodo
Best answer
$userid = qa_get_logged_in_userid(); //id of currently logged in user 
$getFCount = qa_db_read_all_assoc(qa_db_query_sub("
  SELECT userid FROM demo_qa_userfavorites // "demo" is used as example
  WHERE userid = '$userid'
$getFCount = count($getFCount); //count item in array
echo $getFCount;
commented Jun 8, 2016 by Frodo
Thanks for your valuable help !! It worked like a charm...
commented Jun 9, 2016 by donshakespeare
Glad it worked, cheers!