News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Need help .. show avatar

Started by ittiphol, December 09, 2018, 04:28:03 AM

Previous topic - Next topic

ittiphol

How to show Avatar by this code



<?

include('Settings.php');
$conn=mysql_connect($db_server,$db_user,$db_passwd) or die("ติดต่อเซิร์ฟเวอร์ไม่ได้");
$db=mysql_select_db($db_name,$conn) or die("ติดต่อฐานข้อมูลไม่ได้");
$charset = "SET character_set_results=UTF8";
mysql_query($charset) or die('Invalid query: ' . mysql_error());
$ID_BOARD = '1';
$sql = " SELECT * FROM smf_topics ";
$sql .= " INNER JOIN smf_messages ON smf_messages.id_msg = smf_topics.id_first_msg ";
$sql .= " WHERE smf_topics.id_board = '".$ID_BOARD."'   ORDER BY smf_topics.id_topic DESC LIMIT 3";
$res['result'] = mysql_query($sql);     

$cols=4;
$c=$cols;

$default_avatar = 'images/noavatar.png';
echo "

<table width='200px' align='center'>
<tr>
<td align='center' valign='top'>
        <table width="100%" cellpadding="2" oncontextmenu="return false;" style="margin-top:-3px;">
       <tr>
       <td align='center' width="200" valign="top"  onMouseOver="this.bgColor='#C5C7C4'">
";
  if (!empty($rs[$rs['id_member']]['avatar']['image'])){
echo "
', $rs[$rs['id_member']]['avatar']['image'],'';
                    }           
            else {
echo "
<img src="' . $default_avatar .'" alt="default_avatar" width="55" height="55"  class="img-circle" oncontextmenu="return false;" style="margin-top:0em;"/>     ";
                }

echo "

   </td></tr></table>
     ";
  }
}

?>



Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Kindred

Why are you doing direct database queries?

Use the smf functions to protect the requests — or, even better, use the functions and variables already available in SSI.php
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

ittiphol

thank you

in this code i want to know
what code to display avatar and name

please...  :'(

Arantor

What are you actually trying to do?

ittiphol

i just want to show who post by avatar and name
now i make it only message and topic

thank you  :-*

GigaWatt

Do you want to show the avatar of the last member that posted in a specific board, like this?

"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

ittiphol

Quote from: GigaWatt on December 12, 2018, 10:26:42 PM
Do you want to show the avatar of the last member that posted in a specific board, like this?



My code is show last 3 new post (Attachment 01)
but i want to show Avatar and name too  (Attachment 02)

sorry my english

Arantor

You want to show it where exactly?

ittiphol

Quote from: Arantor on December 14, 2018, 02:33:00 AM
You want to show it where exactly?

In the first page (index page)

now



to like this


Kindred

So, you want to edit your forum index page?

In that case, you most definitely should ***NOT*** be using that code that you posted.
1- it is insecure
2- Database queries should not generally be part of the template files
3- it is not necessary since almost all (if not all) the variables are already defined by the core forum


regarding your desire...   showing that little except is not enough. Show us the whole page...
What is your forum URL?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

ittiphol

Quote from: Kindred on December 17, 2018, 09:31:23 AM
So, you want to edit your forum index page?

In that case, you most definitely should ***NOT*** be using that code that you posted.
1- it is insecure
2- Database queries should not generally be part of the template files
3- it is not necessary since almost all (if not all) the variables are already defined by the core forum


regarding your desire...   showing that little except is not enough. Show us the whole page...
What is your forum URL?

This code is works fine
<?

include('Settings.php');
$conn=mysql_connect($db_server,$db_user,$db_passwd) or die("ติดต่อเซิร์ฟเวอร์ไม่ได้");
$db=mysql_select_db($db_name,$conn) or die("ติดต่อฐานข้อมูลไม่ได้");
$charset = "SET character_set_results=UTF8";
mysql_query($charset) or die('Invalid query: ' . mysql_error());
$ID_BOARD = '1';
$sql = " SELECT * FROM smf_topics ";
$sql .= " INNER JOIN smf_messages ON smf_messages.id_msg = smf_topics.id_first_msg ";
$sql .= " WHERE smf_topics.id_board = '".$ID_BOARD."'   ORDER BY smf_topics.id_topic DESC LIMIT 3";
$res['result'] = mysql_query($sql);     

$cols=4;
$c=$cols;
echo "

<table width='200px' align='center'><tr> ";

while ($rs = mysql_fetch_array($res['result'])) {
  $c--;
         $sql_thumb = " SELECT * FROM smf_attachments WHERE id_msg = '".$rs['id_first_msg']."'  AND id_thumb !='0' ORDER BY id_attach ASC  LIMIT 1";
         $res['select_thumb'] = mysql_query($sql_thumb);     
         $rs_t = mysql_fetch_array($res['select_thumb']);
      echo "<td align='center' valign='top' >";
      ?>
      <table width="100%" cellpadding="2" oncontextmenu="return false;" style="margin-top:-3px;">
       <tr>
       <td align='center' width="200" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor='#C5C7C4'" onMouseOut ="this.bgColor = '#FFFFFF'"  style='
         padding:5px 5px 5px 5px;
height:100px;
overflow:hidden;
width120px;
    box-shadow: 0px 0px 1px #1a1a1a;
    border-radius:2px;
    margin-bottom:3px;
         '>
      <?
         if($rs_t['id_thumb']==''){
            echo "<a href='index.php?topic=".$rs['id_topic']."' target='_blank' style='
                  text-decoration:none;'  titlex='".mb_substr($rs['subject'],0,40,'UTF-8')."' class='tooltip'><img src='images/noimage.gif' border='0' style='
            padding:5px 5px 5px 5px;
height:116px;
width:116px;
overflow:hidden;
   
    border-radius:2px;
    margin-bottom:3px;
         ' ></a><br/>";
         }else{
            echo "<a href='index.php?topic=".$rs['id_topic']."' target='_blank'   titlex='".mb_substr($rs['subject'],0,40,'UTF-8')."' class='tooltip'><img src='index.php?action=dlattach;topic=".$rs['id_topic'].";attach=".$rs_t['id_thumb'].";image' style='
            padding:5px 5px 5px 5px;
height:116px;
width:116px;
overflow:hidden;
   
    border-radius:2px;
    margin-bottom:3px;
         ' ></a><br/>";   
         }
         echo "<a href='index.php?topic=".$rs['id_topic']."' target='_blank' style='
                  text-decoration:none;'><font style='
                  text-decoration:none;
  font-size: 80%;
                  color:#3b5998;'>".mb_substr($rs['subject'],0,12,'UTF-8')." ...</font><br><p titlex='".mb_substr($rs['subject'],0,40,'UTF-8')."' class='tooltip2'><img src='images/readmore.png' border='0'></p></a>";
   ?>
   </td></tr></table>
   <?
  echo "</td>";

  if ($c==0) {
    echo "</tr><tr>";
    $c=$cols;
  }
}
echo "</tr>\n</table>\n";
?>


i find the way to show avatar from this code

thank you

Arantor

And it will break when your host upgrades you to PHP 7.

Kindred

and....

Quote from: Kindred on December 17, 2018, 09:31:23 AM
In that case, you most definitely should ***NOT*** be using that code that you posted.
1- it is insecure
2- Database queries should not generally be part of the template files
3- it is not necessary since almost all (if not all) the variables are already defined by the core forum
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

GigaWatt

@ittiphol: Trust me, half baked solutions are never the way to go when you want to build something that's supposed to last.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

ittiphol


Kindred

Of course it is..  you are just starting from the wrong point.
Use smf functions... there is no need to write separate database queries.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

ittiphol

And the SSI function can do this?


Arantor

SSI can do a great many things, as well as calling the parts of SMF that do get avatars.

Thing is, I'm still no clearer in understanding where this should even show and which people it should show.

Biology Forums

I think he wants the most recent posts, along with the title of thread, plus the avatar of the topic starter / (or last poster?) -- that last part I'm not sure. I don't think permissions are problem here, otherwise he'd mention it

Advertisement: