Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.5k 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
i want it show on sidebar when user login.
thanks lot.
by
i want show small version of user profile (username, avatar, points) on sidebar only if user logged in. i don't know how to use this code.only know how to create widget.please help me more details. thank you lot.
by
In output_widget() use above query and output result using $themeobject in loop.
Or give me few days I will make a plugin.
by
thank you very much.
by
query failed:

SELECT *FROM qa_users^,qa_userpoints WHERE qa_userpoints.userid=qa_users.userid

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '^,qa_userpoints WHERE qa_userpoints.userid=qa_users.userid' at line 1
by
It is working fine when I tested. Check my edited answer above. I have added tested function. You can use directly that function and get any value from qa_users and qa_userpoints tables.

Hope this will helps you.
by
still can't work it. i put this code in my qa-siderbar-profile-widget.php
and try in function output_widget. only print out "Array" this result.
by
This function works in layer. I have tested right before $this->page_title_error(); and giving output without any error. If you are using this for widget than you might need to use $themeobject->output not $this->output
by
Yes! it work. but every user in this site. how about only current login user points and avatar?

Output
----------------
admin has 3 points
yasin has 6 points
ياسىن has 0 points
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
...