Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: ittiphol on December 09, 2018, 04:28:03 AM

Title: Need help .. show avatar
Post by: ittiphol on December 09, 2018, 04:28:03 AM
How to show Avatar by this code

Code: [Select]

<?

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>
     ";
  }
}

?>


Title: Re: Need help .. show avatar
Post by: Pipke on December 09, 2018, 12:09:53 PM
Maybe you can use this instead Avatars on Board and/or MessageIndex (http://custom.simplemachines.org/mods/index.php?mod=4107)
Title: Re: Need help .. show avatar
Post by: Kindred on December 09, 2018, 03:42:28 PM
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
Title: Re: Need help .. show avatar
Post by: ittiphol on December 12, 2018, 04:45:08 AM
thank you

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

please...  :'(
Title: Re: Need help .. show avatar
Post by: Arantor on December 12, 2018, 05:08:15 AM
What are you actually trying to do?
Title: Re: Need help .. show avatar
Post by: ittiphol on December 12, 2018, 09:56:54 PM
i just want to show who post by avatar and name
now i make it only message and topic

thank you  :-*
Title: Re: Need help .. show avatar
Post by: 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?

(https://i.postimg.cc/63d8kNWm/SHOT8707.png)
Title: Re: Need help .. show avatar
Post by: ittiphol on December 14, 2018, 01:29:11 AM
Do you want to show the avatar of the last member that posted in a specific board, like this?

(https://i.postimg.cc/63d8kNWm/SHOT8707.png)

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

sorry my english
Title: Re: Need help .. show avatar
Post by: Arantor on December 14, 2018, 02:33:00 AM
You want to show it where exactly?
Title: Re: Need help .. show avatar
Post by: ittiphol on December 14, 2018, 11:49:18 PM
You want to show it where exactly?

In the first page (index page)

now

(https://www.simplemachines.org/community/index.php?action=dlattach;topic=563900.0;attach=260409;image)

to like this

(https://www.simplemachines.org/community/index.php?action=dlattach;topic=563900.0;attach=260411;image)
Title: Re: Need help .. show avatar
Post by: 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?
Title: Re: Need help .. show avatar
Post by: ittiphol on December 21, 2018, 11:14:56 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
Code: [Select]
<?

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
Title: Re: Need help .. show avatar
Post by: Arantor on December 21, 2018, 12:05:56 PM
And it will break when your host upgrades you to PHP 7.
Title: Re: Need help .. show avatar
Post by: Kindred on December 21, 2018, 12:17:53 PM
and....

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
Title: Re: Need help .. show avatar
Post by: GigaWatt on December 21, 2018, 09:03:52 PM
@ittiphol: Trust me, half baked solutions are never the way to go when you want to build something that's supposed to last.
Title: Re: Need help .. show avatar
Post by: ittiphol on December 22, 2018, 10:14:48 AM
So... it's not possible ?  :-\
Title: Re: Need help .. show avatar
Post by: Kindred on December 22, 2018, 11:20:34 AM
Of course it is..  you are just starting from the wrong point.
Use smf functions... there is no need to write separate database queries.
Title: Re: Need help .. show avatar
Post by: ittiphol on December 22, 2018, 06:39:32 PM
And the SSI function can do this?

(https://www.simplemachines.org/community/index.php?action=dlattach;topic=563900.0;attach=260411;image)
Title: Re: Need help .. show avatar
Post by: Arantor on December 22, 2018, 06:49:06 PM
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.
Title: Re: Need help .. show avatar
Post by: Study Force on December 23, 2018, 02:47:19 AM
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
Title: Re: Need help .. show avatar
Post by: Arantor on December 23, 2018, 04:10:00 AM
Assuming that’s right (and that’s not clear), then display it where exactly? On the board index? Instead of the board index? (If instead of board index, are we then pushing the board index to another action so it’s still available?)
Title: Re: Need help .. show avatar
Post by: xTyler on January 05, 2019, 02:49:42 PM
If you are trying to add something like this:
(https://i.imgur.com/TAJHDdq.png)
Then i think it would be best to install a portal to display recent posters or if you wish to create your own the you need to use the correct smf variables in place and not call it separately from the database.