Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Torrent Trader (http://www.bvlist.com/forumdisplay.php?f=29)
-   -   Avatar in Shoutbox (http://www.bvlist.com/showthread.php?t=7113)

psylodesign 22nd October 2011 01:36

Avatar in Shoutbox
 
Hi guys,
i am working for add the avatar near the pseudo in shoutbox but i am a noob with SQL..
Please anyone can help me?
PHP Code:

mysql_query("SELECT avatar FROM `users` WHERE id = $row[avatar] ");
echo    
'</td><td style="font-size: 12px; padding-left: 5px"><img src=  '.$row['avatar'].'> <a href="'.$site_config['SITEURL'].'/account-details.php?id='.$row['userid'].'" target="_parent"><b>' .$user':</b></a>&nbsp;&nbsp;'.nl2br(format_comment($row['message']));
    echo    
'</td></tr>'

is my best way be it don't works

joeroberts 22nd October 2011 08:33

wow thats off :sos:
PHP Code:

$bimg2 = @mysql_fetch_array(@mysql_query("SELECT avatar FROM users WHERE id=" $row['userid']));
$avatar $bimg2['avatar'];
if (!
$avatar) {
    
$avatar $site_config['SITEURL']."/images/default_avatar.gif";
}
echo    
'</td><td style="font-size: 12px; padding-left: 5px"><img src=  '.$avatar.'> <a href="'.$site_config['SITEURL'].'/account-details.php?id='.$row['userid'].'" target="_parent"><b>' .$user':</b></a>&nbsp;&nbsp;'.nl2br(format_comment($row['message'])); 


psylodesign 22nd October 2011 09:42

Quote:

Originally Posted by joeroberts (Post 30762)
wow thats off :sos:

:lol: i was sure than that's off ,
thx a lot it works perfect :friend:

putyn 23rd October 2011 18:17

Quote:

Originally Posted by joeroberts (Post 30762)
PHP Code:

$bimg2 = @mysql_fetch_array(@mysql_query("SELECT avatar FROM users WHERE id=" $row['userid']));
$avatar $bimg2['avatar'];
if (!
$avatar) {
    
$avatar $site_config['SITEURL']."/images/default_avatar.gif";
}
echo    
'</td><td style="font-size: 12px; padding-left: 5px"><img src=  '.$avatar.'> <a href="'.$site_config['SITEURL'].'/account-details.php?id='.$row['userid'].'" target="_parent"><b>' .$user':</b></a>&nbsp;&nbsp;'.nl2br(format_comment($row['message'])); 


really a query in a loop ? thats not really smart , also people stopped using mysql_fetch_array a long time ago - its bad for performance

hint LEFT JOIN

Joe 23rd October 2011 18:35

So when u add your avatar to shoutbox will that slow your site down . As now you have to fetch it plus you will need to make your shoutbox even bigger ??

Call me crazy but ?:shock:

joeroberts 23rd October 2011 18:59

Quote:

Originally Posted by putyn (Post 30792)

hint LEFT JOIN

I like to use this to like so
PHP Code:

                $sql "SELECT S.*, U.id as uid, U.can_do as can_do, U.donator AS donator, U.warned as warned, U.level as level, IF(U.name IS NULL, U.username, U.name) as user_name FROM ".$db_prefix."_shouts S LEFT JOIN ".$db_prefix."_users U ON S.user = U.id WHERE S.id_to = '0' OR S.id_to = '".$user->id."' OR (S.user = '".$user->id."' AND S.id_to  >'0')  ORDER BY  posted DESC LIMIT ".$shout_config['shouts_to_show'].""

it dont slow it down no extra querys
and as for enlarging you shout box all you would have to do is make the avatar a set size

romano1 10th January 2013 18:17

This is very fine, but where to put it?
in shoutbox.php but where?

firefly 10th January 2013 18:25

Quote:

Originally Posted by romano1 (Post 38746)
This is very fine, but where to put it?
in shoutbox.php but where?

It will go in your shoutbox.php

Post your shoutbox.php here and please wrap it in php tags.

iCode 10th January 2013 18:34

Quote:

Originally Posted by Joe (Post 30793)
So when u add your avatar to shoutbox will that slow your site down . As now you have to fetch it plus you will need to make your shoutbox even bigger ??

Call me crazy but ?:shock:

My thoughts exactly

romano1 10th January 2013 18:37

Quote:

Originally Posted by firefly (Post 38748)
It will go in your shoutbox.php

You will need to add avatar, to the query to.

Post your shoutbox.php here and please wrap it in php tags.

Thank you firefly, when i get home wil do.

Bump:
Quote:

Originally Posted by firefly (Post 38748)
It will go in your shoutbox.php

Post your shoutbox.php here and please wrap it in php tags.

Code:

//
//  TorrentTrader v2.x
//      $LastChangedDate: 2012-06-14 17:31:26 +0100 (Thu, 14 Jun 2012) $
//      $LastChangedBy: torrenttrader $
//
//      http://www.torrenttrader.org
//
//
require_once("backend/functions.php");
dbconn(false);
?>

if ($site_config['SHOUTBOX']){
//DELETE MESSAGES
if (isset($_GET['del'])){

    if (is_numeric($_GET['del'])){
        $query = "SELECT * FROM shoutbox WHERE msgid=".$_GET['del'] ;
        $result = SQL_Query_exec($query);
    }else{
        echo "invalid msg id STOP TRYING TO INJECT SQL";
        exit;
    }

    $row = mysql_fetch_row($result);
       
    if ($row && ($CURUSER["edit_users"]=="yes" || $CURUSER['username'] == $row[1])) {
        $query = "DELETE FROM shoutbox WHERE msgid=".$_GET['del'] ;
        write_log("Shout Deleted: Deleted by  ".$CURUSER['username']."");
        SQL_Query_exec($query);   
    }
}

//INSERT MESSAGE
if (!empty($_POST['message']) && $CURUSER) {   
    $_POST['message'] = sqlesc($_POST['message']);
    $query = "SELECT COUNT(*) FROM shoutbox WHERE message=".$_POST['message']." AND user='".$CURUSER['username']."' AND UNIX_TIMESTAMP('".get_date_time()."')-UNIX_TIMESTAMP(date) < 30";
    $result = SQL_Query_exec($query);
    $row = mysql_fetch_row($result);

    if ($row[0] == '0') {
        $query = "INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, '".$CURUSER['username']."', ".$_POST['message'].", '".get_date_time()."', '".$CURUSER['id']."')";
        SQL_Query_exec($query);
    }
}

//GET CURRENT USERS THEME AND LANGUAGE
if ($CURUSER){
    $ss_a = @mysql_fetch_assoc(@SQL_Query_exec("select uri from stylesheets where id=" . $CURUSER["stylesheet"]));
    if ($ss_a)
        $THEME = $ss_a["uri"];
}else{//not logged in so get default theme/language
    $ss_a = mysql_fetch_assoc(SQL_Query_exec("select uri from stylesheets where id='" . $site_config['default_theme'] . "'"));
    if ($ss_a)
        $THEME = $ss_a["uri"];
}

if(!isset($_GET['history'])){
?>


<?php echo $site_config['SITENAME'] . T_("SHOUTBOX"); ?>






    echo '
';
}else{
   
    if ($site_config["MEMBERSONLY"]) {
        loggedinonly();
    }
   
    stdhead();
    begin_frame(T_("SHOUTBOX_HISTORY"));
    echo '
';

    $query = 'SELECT COUNT(*) FROM shoutbox';
    $result = SQL_Query_exec($query);
    $row = mysql_fetch_row($result);
    echo '
Pages: ';
    $pages = round($row[0] / 100) + 1;
    $i = 1;
    while ($pages > 0){
        echo "[".$i."] ";
        $i++;
        $pages--;
    }

    echo '
';
}

if (isset($_GET['history'])) {
    if (isset($_GET['page'])) {
        if($_GET['page'] > '1') {
            $lowerlimit = $_GET['page'] * 100 - 100;
            $upperlimit = $_GET['page'] * 100;
        }else{
            $lowerlimit = 0;
            $upperlimit = 100;
        }
    }else{
        $lowerlimit = 0;
        $upperlimit = 100;
    }   
    $query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT '.$lowerlimit.','.$upperlimit;
}else{
    $query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT 20';
}


$result = SQL_Query_exec($query);
$alt = false;

while ($row = mysql_fetch_assoc($result)) {
    if ($alt){   
        echo '';
        $alt = false;
    }else{
        echo '';
        $alt = true;
    }

    echo '';
}
?>

';
    echo "
";

    echo date('jS M, g:ia', utc_to_tz_time($row['date']));
   

    echo "
";

    if ( ($CURUSER["edit_users"]=="yes") || ($CURUSER['username'] == $row['user']) ){
        echo "";
    }

    echo    '
'.$row['user'].':  '.nl2br(format_comment($row['message']));
    echo    '





//if the user is logged in, show the shoutbox, if not, dont.
if(!isset($_GET['history'])) {
    if (isset($_COOKIE["pass"])){
        echo "
";
        echo "
";
        echo "";
        echo "";
        echo "";
        echo "";
        echo "";
        echo "
";
        echo "";
        echo "
";
        echo "";
        echo "
";
        echo ''.T_("MORE_SMILIES").'';
        echo ' - '.T_("TAGS").'';
        echo "";
        echo "".T_("REFRESH")."";             
        echo " - ".T_("HISTORY")."";
        echo "
";
        echo "
";
    }else{
        echo "
".T_("SHOUTBOX_MUST_LOGIN")."
";
    }
}

if(!isset($_GET['history'])){
    echo "";
}else{
    end_frame();
    stdfoot();
}


}//END IF $SHOUTBOX
else{
    echo T_("SHOUTBOX_DISABLED");
}
?>



All times are GMT +2. The time now is 00:20.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.