I’m assuming this is a different comments table in your database than the one that WordPress creates. You’re getting the user ID for the avatar from here:
$id=$row['Id_user'];
Which means you have a column called Id_user in your comments table, correct?
So, when you’re creating your comments, you’ll have to take the user ID of the logged-in user and save it to that column. Also, you should prevent users who aren’t logged in from being able to create comments, because then I’m guessing the comment is saving the Id_user with a 0. Alternatively, you could do something like this to allow non-registered users to leave comments, as long as they put an e-mail address:
$id=$row['Id_user'];
$email=$row['com_email'];
$id_or_email = !empty($id) ? $id : $email;
…
get_wp_user_avatar($id_or_email, 40);
But, initially you’ll need to pass the value of $idaccount to Id_user.
Thread Starter
Theopt
(@theopt)
Well, then I did all that already 😐 so why its not working. because Im filling the DB with the values on idaccount.
I guess I’m not following what you’re saying. The values for Id_user look correct in your database? Then the way you’ve written the query for the data is incorrect. I would probably rewrite your query like this:
<?php
global $wpdb;
$comments = $wpdb->get_results(SELECT * FROM $wpdb->your_comments_table
WHERE whatever_youre_looking_for = 'the_right_answer'
ORDER BY date_column_perhaps);
foreach($comments as $comment) { ?>
<li class="panel" style="margin:10px; list-style-type: none;">
<?php echo get_wp_user_avatar($comment->Id_user, 40); ?>
<span class="com_name"><?php echo $comment->name; ?></span><br />
<?php echo $comment->body; ?>
</li>
<?php } ?>