We have this bit of code on our torrents-details.php that works great, it resolves peer data very well, but usernames/avatars are completely incorrect. I can't figure this out, but this is our code:
<?
// Updated Stats & table with avatar and cleaner design - Feb 28, 2020
if ($row["external"] != 'yes') {
echo "<br /><span style='margin-left:-10px'><b>" . T_("PEERS_LIST") . "</b> <small><span style='color:#ED2324'>beta</span></small></b></span><br />";
$query = SQL_Query_exec("SELECT * FROM peers WHERE torrent = $id ORDER BY seeder DESC");
$result = mysql_num_rows($query);
if ($result == 0) {
echo "<span style='font-weight:normal;margin-left:-10px'>No active peers on the network</span><br />";
} elseif ($row["external"] = 'yes' && $CURUSER) {
?>
<!-- Stats Table Styling -->
<style>.table_col1, .table_tr { border-top:1px solid #fff; background:#F5F5F5; font-weight: normal; text-align:center; margin-left:-20px } .table_head { font-weight: normal; text-align:left; padding-left:10px }</style>
<div style="margin-left:-20px;width:100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="table_table">
<tr>
<th class="table_head"><? echo T_("PORT"); ?></th>
<th class="table_head">UL</th>
<th class="table_head">DL</th>
<!--<th class="table_head"><? echo T_("RATIO"); ?></th>-->
<th class="table_head"><? echo T_("_LEFT_"); ?></th>
<th class="table_head"><? echo "%"; ?></th>
<th class="table_head"><? echo T_("SEED"); ?></th>
<th class="table_head"><? echo T_("CONNECTED_SHORT"); ?></th>
<th class="table_head"><? echo T_("CLIENT"); ?></th>
<th class="table_head"><? echo T_("USER_SHORT"); ?></th>
</tr>
<?
while ($row1 = mysql_fetch_assoc($query)) {
if ($row1["downloaded"] > 0) {
$ratio = $row1["uploaded"] / $row1["downloaded"];
$ratio = number_format($ratio, 3);
} else {
$ratio = "---";
}
$percentcomp = sprintf("%.2f", 100 * (1 - ($row1["to_go"] / $row["size"])));
//if ($site_config["MEMBERSONLY"]) {
//$res = SQL_Query_exec("SELECT users.id, users.username, users.avatar, users.privacy FROM users LEFT JOIN peers ON peers.userid = users.id WHERE users.id=" . $row1["userid"]); // Testing, seems to work as-is?
$res = SQL_Query_exec("SELECT id, username, avatar, privacy FROM users WHERE id=" . $row1["userid"]);
$arr = mysql_fetch_array($res);
//$arr["username"] = "<a href='/user/?id=$arr[id]'>" . class_user($arr[username]) . "</a>";
$arr["username"] = "<a href='$site_config[SITEURL]/user/?id=$arr[id]'><img src='$site_config[SITEURL]/$arr[avatar]' style='border-radius:50%;height:45px;width:45px'></a>";
//}
if (!$arr["username"])
//$arr["username"] = "Unknown User";
$arr["username"] = "<img src='" . $site_config['SITEURL'] . "/images/noavatar.png' style='border-radius:50%;height:45px;width:45px' />";
if ($arr["privacy"] != "strong" || ($CURUSER["control_panel"] == "yes")) { // If Admin, show the extended details, or else show basic details to everyone else
print("<tr class='table_tr'><td class='table_col2'>66" . $row1["port"] . "</td><td class='table_col1' style='width:300px'>" . mksize($row1["uploaded"]) . "</td><td class='table_col2' style='width:300px'>" . mksize($row1["downloaded"]) . "</td><td class='table_col1' style='display:none'>" . $ratio . "</td><td class='table_col2' style='width:300px'>" . mksize($row1["to_go"]) . "</td><td class='table_col1'>" . $percentcomp . "%</td><td class='table_col2'>$row1[seeder]</td><td class='table_col1' style='text-transform:capitalize;font-weight:bold'>$row1[connectable]</td><td class='table_col2' style='padding-left:15px;padding-right:15px'>" . htmlspecialchars($row1["client"]) . "</td><td class='table_col1' width='90' align='right'>$arr[username]</td></tr>");
} else {
print("<tr><td class='table_col2'>" . $row1["port"] . "</td><td class='table_col1'>" . mksize($row1["uploaded"]) . "</td><td class='table_col2'>" . mksize($row1["downloaded"]) . "</td><td class='table_col1'>" . $ratio . "</td><td class='table_col2'>" . mksize($row1["to_go"]) . "</td><td class='table_col1'>" . $percentcomp . "%</td><td class='table_col2'>$row1[seeder]</td><td class='table_col1'>$row1[connectable]</td><td class='table_col2'>" . htmlspecialchars($row1["client"]) . "</td><td class='table_col1'>Private</td></tr>");
}
}
echo "</table></div>";
}
}
?>
I've tried playing with
SQL_Query_exec("SELECT id, username, avatar, privacy FROM users WHERE id=" . $row1["userid"]);
And trying available variables, but it only takes $row1. So I went to see about JOINing tables, since the code is taking the long way around to perform this anyway:
$res = SQL_Query_exec("SELECT users.id, users.username, users.avatar, users.privacy FROM users LEFT JOIN peers ON peers.userid = users.id WHERE users.id=" . $row1["userid"]);
Still no luck. Has this little feature even worked for anybody using TorrentTrader? If so, its safe to assume I've done something to
announce.php - I just need confirmation on if this was originally a "experimental" feature or not. I can start overwriting files and crossing my fingers but that doesn't play nice with a actively updated 'peers' table and just causing problems.
Seems easier to just write-off this and get rid of it but.. hey the code in there, why not utilize it?
[ATTACH type="full"]5397[/ATTACH]