Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.8k views
in Q2A Core by
get username, points, avatar then show it on sidebar? how can i do this?
Q2A version: 1.5.4

2 Answers

+2 votes
by
selected by
 
Best answer

You can try with below code for layer but to place this in sidebar you may need to create a widget. I havn't tested this code but it should work.

Part Deleted

Or you can check my two plugins and modify according to your need "new-members-widget" and "q2am-recent-questions"

 
EDIT 1: Added Tested Function To Get All User Data
 
Check this below function. I have tested it and working completely fine.
 
function get_user_data()
        {
            $query = "                
                SELECT * 
                FROM ^users, ^userpoints 
                WHERE ^userpoints.userid = ^users.userid            
            ";
            
            $query_sub = qa_db_query_sub($query);
            
            while ($row = qa_db_read_one_assoc($query_sub, true)):
                $this->output(
                    '<UL>',
                        '<LI>',
                            $row['handle'].' has '.$row['points']. ' points',
                        '</LI>',
                    
                    '</UL>'
                );
            endwhile;
        }

 

Getting Below Output

 

EDIT 2: Added Tested Function To Get Logged In User Data

// This is the query function

function get_user_data()

        {
 
$loggedin_userid = qa_get_logged_in_userid();
            $query = "                
                SELECT * 
                FROM ^users, ^userpoints 
                WHERE ^users.userid = $loggedin_userid
AND ^userpoints.userid = $loggedin_userid
LIMIT 1
            ";
 
            $query_sub = qa_db_query_sub($query);
            
            while ($row = qa_db_read_one_assoc($query_sub, true)):
                $this->output(
                    '<UL>',
                        '<LI>',
                            $row['handle'].' has '.$row['points']. ' points',
                        '</LI>',
                    
                    '</UL>'
                );
            endwhile;
        }
 
// Use this where you want to call but make sure if you are using this in widget than you may need to use $themeobject->output instead of $this->output
 
if (qa_is_logged_in())
$this->get_user_data();
 
 
EDIT 3: TO Display Only Usename and Points Use This
 
$userhandle = qa_get_logged_in_handle();
$userpoints = qa_get_logged_in_points();
 
$this->output($userhandle . ' ' .$userpoints);
by
You didn't mention in your question. Anyways check my Edit 2 to get only logged in user data.

There may be some other way to get logged in user data but this is one way I would do. If someone know any better way I would love to know that too.

Also if you are not going to use all field than you can use columns name instead of *
by
One more important thing. If you want to display only usename and points than use my 3rd edit code. No need to fetch query. Query is require only if you need to pull more data than core function.
by
Yep! EDIT 3 did the trick. million thanks bro.
by
how about avatar? also need display logged user avatar.
0 votes
by
hello ,,

i want that too but can't able to know which file to add this code

i hope any one help me
...