Hello, can you tell me how to display the ratio in memberlist.php
$res = SQL_Query_exec("SELECT uploaded, downloaded FROM users WHERE id = $CURUSER[id]");
while ($row = mysqli_fetch_assoc($res)) {
if ($row['downloaded'] > 0)
{
$ratio = $row['uploaded'] / $row['downloaded'];
$ratio = number_format($ratio, 2);
$color = get_ratio_color($ratio);
if ($color)
$ratio = "<font color=#ffff00>$ratio</font>";
} else if ($row['uploaded'] > 0)
$ratio = 'Inf.';
}
echo $ratio;
}
"m-jay, post: 69544, member: 20288":
You can try this, depending where you put it the id needs changing for show we use $CUR[user]
$res = SQL_Query_exec("SELECT uploaded, downloaded FROM users WHERE id = $CURUSER[id]");
while ($row = mysqli_fetch_assoc($res)) {
if ($row['downloaded'] > 0)
{
$ratio = $row['uploaded'] / $row['downloaded'];
$ratio = number_format($ratio, 2);
$color = get_ratio_color($ratio);
if ($color)
$ratio = "<font color=#ffff00>$ratio</font>";
} else if ($row['uploaded'] > 0)
$ratio = 'Inf.';
}
echo $ratio;
}
Test on index.php at top (above check block) if it works we look at you memberlist.php
function get_ratio_color($ratio)
{
if ($ratio < 0.1) {
return "#ff0000";
}
if ($ratio < 0.2) {
return "#ee0000";
}
if ($ratio < 0.3) {
return "#dd0000";
}
if ($ratio < 0.4) {
return "#cc0000";
}
if ($ratio < 0.5) {
return "#bb0000";
}
if ($ratio < 0.6) {
return "#aa0000";
}
if ($ratio < 0.7) {
return "#990000";
}
if ($ratio < 0.8) {
return "#880000";
}
if ($ratio < 0.9) {
return "#770000";
}
if ($ratio < 1) {
return "#660000";
}
return "#000000";
"m-jay, post: 69546, member: 20288":
It's on v2.08
function get_ratio_color($ratio)
{
if ($ratio < 0.1) {
return "#ff0000";
}
if ($ratio < 0.2) {
return "#ee0000";
}
if ($ratio < 0.3) {
return "#dd0000";
}
if ($ratio < 0.4) {
return "#cc0000";
}
if ($ratio < 0.5) {
return "#bb0000";
}
if ($ratio < 0.6) {
return "#aa0000";
}
if ($ratio < 0.7) {
return "#990000";
}
if ($ratio < 0.8) {
return "#880000";
}
if ($ratio < 0.9) {
return "#770000";
}
if ($ratio < 1) {
return "#660000";
}
return "#000000";
"m-jay, post: 69548, member: 20288":
If you use it mate will you test the other code, once I know the syntax works I can easily add it to the memberlist table for niki
<?php
//
// TorrentTrader v3.x
require_once("backend/functions.php");
dbconn();
loggedinonly();
if ($CURUSER["view_users"]=="no")
show_error_msg(T_("ERROR"), T_("NO_USER_VIEW"), 1);
$search = trim($_GET['search']);
$class = (int) $_GET['class'];
$letter = trim($_GET['letter']);
if (!$class)
unset($class);
$q = $query = null;
if ($search) {
$query = "username LIKE " . sqlesc("%$search%") . " AND status='confirmed'";
if ($search) {
$q = "search=" . htmlspecialchars($search);
}
} elseif ($letter) {
if (strlen($letter) > 1)
unset($letter);
if ($letter == "" || strpos("abcdefghijklmnopqrstuvwxyz", $letter) === false) {
unset($letter);
} else {
$query = "username LIKE '$letter%' AND status='confirmed'";
}
$q = "letter=$letter";
}
if (!$query) {
$query = "status='confirmed'";
}
if ($class) {
$query .= " AND class=$class";
$q .= ($q ? "&" : "") . "class=$class";
}
stdhead(T_("USERS"));
begin_frame(T_("USERS"));
print("<br /><form method='get' action='memberlist.php'>\n");
print(T_("SEARCH").": <input type='text' size='30' name='search' />\n");
print("<select name='class'>\n");
print("<option value='-'>(any class)</option>\n");
$res = SQL_Query_exec("SELECT group_id, level FROM groups");
while ($row = mysqli_fetch_array($res)) {
print("<option value='$row[group_id]'" . ($class && $class == $row['group_id'] ? " selected='selected'" : "") . ">".htmlspecialchars($row['level'])."</option>\n");
}
print("</select>\n");
print("<input type='submit' value='".T_("SEARCH")."' />\n");
print("</form>\n");
print("<p>\n");
print("<a href='memberlist.php'><b>".T_("ALL")."</b></a> - \n");
foreach (range("a", "z") as $l) {
$L = strtoupper($l);
if ($l == $letter)
print("<b>$L</b>\n");
else
print("<a href='memberlist.php?letter=$l'><b>$L</b></a>\n");
}
print("</p>\n");
$page = (int) $_GET['page'];
$perpage = 25;
$res = SQL_Query_exec("SELECT COUNT(*) FROM users WHERE $query");
$arr = mysqli_fetch_row($res);
$pages = floor($arr[0] / $perpage);
if ($pages * $perpage < $arr[0])
++$pages;
if ($page < 1)
$page = 1;
else
if ($page > $pages)
$page = $pages;
for ($i = 1; $i <= $pages; ++$i)
if ($i == $page)
$pagemenu .= "$i\n";
else
$pagemenu .= "<a href='?$q&page=$i'>$i</a>\n";
if ($page == 1)
$browsemenu .= "";
// $browsemenu .= "[Prev]";
else
$browsemenu .= "<a href='?$q&page=" . ($page - 1) . "'>[Prev]</a>";
$browsemenu .= " ";
if ($page == $pages)
$browsemenu .= "";
// $browsemenu .= "[Next]";
else
$browsemenu .= "<a href='?$q&page=" . ($page + 1) . "'>[Next]</a>";
$offset = ($page * $perpage) - $perpage;
$res = SQL_Query_exec("SELECT users.*, groups.level FROM users LEFT JOIN groups ON groups.group_id=users.class WHERE $query ORDER BY username LIMIT $offset,$perpage");
begin_table();
print("<tr><th class='table_head'>" . T_("USERNAME") . "</th><th class='table_head'>" . T_("REGISTERED") . "</th><th class='table_head'>" . T_("LAST_ACCESS") . "</th><th class='table_head'>" . T_("CLASS") . "</th><th class='table_head'>" . T_("COUNTRY") . "</th><th class='table_head'>" . T_("RATIO") . "</th></tr>\n");
while ($arr = mysqli_fetch_assoc($res)) {
$cres = SQL_Query_exec("SELECT name,flagpic FROM countries WHERE id=$arr[country]");
if ($carr = mysqli_fetch_assoc($cres)) {
$country = "<td align=\"center\" class='table_col1' style='padding: 0px'><img src='$site_config[SITEURL]/images/countries/$carr[flagpic]' title='".htmlspecialchars($carr['name'])."' alt='".htmlspecialchars($carr['name'])."' /></td>";
} else {
$country = "<td align=\"center\" class='table_col1' style='padding: 0px'><img src='$site_config[SITEURL]/images/countries/unknown.gif' alt='Unknown' /></td>";
}
$r = SQL_Query_exec("SELECT uploaded, downloaded FROM users WHERE id=$arr[id]");
$user = mysqli_fetch_assoc($r);
if ($user["downloaded"] > 0) {
$ratio = number_format($user["uploaded"] / $user["downloaded"], 2);
}else{
$ratio = "Inf";
}
/* if ($arr['added'] == '0000-00-00 00:00:00')
$arr['added'] = '-';
if ($arr['last_access'] == '0000-00-00 00:00:00')
$arr['last_access'] = T_("NEVER");*/
print("<tr><td class='table_col1' align='left'><a href='account-details.php?id=$arr[id]'><b>$arr[username]</b></a>" .($arr["donated"] > 0 ? "<img src='$site_config[SITEURL]/images/star.png' border='0' alt='Donated' />" : "")."</td>" .
"<td align=\"center\" class='table_col2'>".utc_to_tz($arr["added"])."</td><td align=\"center\" class='table_col1'>".utc_to_tz($arr["last_access"])."</td>".
"<td class='table_col2' align='center'>" . T_($arr["level"]) . "</td>$country ". "<td class='table_col2' align='center'>" . $ratio . "</td></tr>\n");
}
end_table();
print("<p>$pagemenu<br />$browsemenu</p>");
end_frame();
stdfoot();
?>
<?php
//
// TorrentTrader v3.x
require_once("backend/functions.php");
dbconn();
loggedinonly();
if ($CURUSER["view_users"]=="no")
show_error_msg(T_("ERROR"), T_("NO_USER_VIEW"), 1);
$search = trim($_GET['search']);
$class = (int) $_GET['class'];
$letter = trim($_GET['letter']);
if (!$class)
unset($class);
$q = $query = null;
if ($search) {
$query = "username LIKE " . sqlesc("%$search%") . " AND status='confirmed'";
if ($search) {
$q = "search=" . htmlspecialchars($search);
}
} elseif ($letter) {
if (strlen($letter) > 1)
unset($letter);
if ($letter == "" || strpos("abcdefghijklmnopqrstuvwxyz", $letter) === false) {
unset($letter);
} else {
$query = "username LIKE '$letter%' AND status='confirmed'";
}
$q = "letter=$letter";
}
if (!$query) {
$query = "status='confirmed'";
}
if ($class) {
$query .= " AND class=$class";
$q .= ($q ? "&" : "") . "class=$class";
}
stdhead(T_("USERS"));
begin_frame(T_("USERS"));
print("<br /><form method='get' action='memberlist.php'>\n");
print(T_("SEARCH").": <input type='text' size='30' name='search' />\n");
print("<select name='class'>\n");
print("<option value='-'>(any class)</option>\n");
$res = SQL_Query_exec("SELECT group_id, level FROM groups");
while ($row = mysqli_fetch_array($res)) {
print("<option value='$row[group_id]'" . ($class && $class == $row['group_id'] ? " selected='selected'" : "") . ">".htmlspecialchars($row['level'])."</option>\n");
}
print("</select>\n");
print("<input type='submit' value='".T_("SEARCH")."' />\n");
print("</form>\n");
print("<p>\n");
print("<a href='memberlist.php'><b>".T_("ALL")."</b></a> - \n");
foreach (range("a", "z") as $l) {
$L = strtoupper($l);
if ($l == $letter)
print("<b>$L</b>\n");
else
print("<a href='memberlist.php?letter=$l'><b>$L</b></a>\n");
}
print("</p>\n");
$page = (int) $_GET['page'];
$perpage = 25;
$res = SQL_Query_exec("SELECT COUNT(*) FROM users WHERE $query");
$arr = mysqli_fetch_row($res);
$pages = floor($arr[0] / $perpage);
if ($pages * $perpage < $arr[0])
++$pages;
if ($page < 1)
$page = 1;
else
if ($page > $pages)
$page = $pages;
for ($i = 1; $i <= $pages; ++$i)
if ($i == $page)
$pagemenu .= "$i\n";
else
$pagemenu .= "<a href='?$q&page=$i'>$i</a>\n";
if ($page == 1)
$browsemenu .= "";
// $browsemenu .= "[Prev]";
else
$browsemenu .= "<a href='?$q&page=" . ($page - 1) . "'>[Prev]</a>";
$browsemenu .= " ";
if ($page == $pages)
$browsemenu .= "";
// $browsemenu .= "[Next]";
else
$browsemenu .= "<a href='?$q&page=" . ($page + 1) . "'>[Next]</a>";
$offset = ($page * $perpage) - $perpage;
$res = SQL_Query_exec("SELECT users.*, groups.level FROM users LEFT JOIN groups ON groups.group_id=users.class WHERE $query ORDER BY username LIMIT $offset,$perpage");
begin_table();
print("<tr><th class='table_head'>" . T_("USERNAME") . "</th><th class='table_head'>" . T_("REGISTERED") . "</th><th class='table_head'>" . T_("LAST_ACCESS") . "</th><th class='table_head'>" . T_("CLASS") . "</th><th class='table_head'>" . T_("COUNTRY") . "</th><th class='table_head'>" . T_("RATIO") . "</th></tr>\n");
while ($arr = mysqli_fetch_assoc($res)) {
$cres = SQL_Query_exec("SELECT name,flagpic FROM countries WHERE id=$arr[country]");
if ($carr = mysqli_fetch_assoc($cres)) {
$country = "<td align=\"center\" class='table_col1' style='padding: 0px'><img src='$site_config[SITEURL]/images/countries/$carr[flagpic]' title='".htmlspecialchars($carr['name'])."' alt='".htmlspecialchars($carr['name'])."' /></td>";
} else {
$country = "<td align=\"center\" class='table_col1' style='padding: 0px'><img src='$site_config[SITEURL]/images/countries/unknown.gif' alt='Unknown' /></td>";
}
/// Ratio added below
$r = SQL_Query_exec("SELECT uploaded, downloaded FROM users WHERE id=$arr[id]");
$user = mysqli_fetch_assoc($r);
if ($user["downloaded"] > 0) {
$ratio = number_format($user["uploaded"] / $user["downloaded"], 2);
$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
}else{
$ratio = "Inf";
}
/// End Ratio addition
/* if ($arr['added'] == '0000-00-00 00:00:00')
$arr['added'] = '-';
if ($arr['last_access'] == '0000-00-00 00:00:00')
$arr['last_access'] = T_("NEVER");*/
print("<tr><td class='table_col1' align='left'><a href='account-details.php?id=$arr[id]'><b>$arr[username]</b></a>" .($arr["donated"] > 0 ? "<img src='$site_config[SITEURL]/images/star.png' border='0' alt='Donated' />" : "")."</td>" .
"<td align=\"center\" class='table_col2'>".utc_to_tz($arr["added"])."</td><td align=\"center\" class='table_col1'>".utc_to_tz($arr["last_access"])."</td>".
"<td class='table_col2' align='center'>" . T_($arr["level"]) . "</td>$country ". "<td class='table_col2' align='center'>" . $ratio . "</td></tr>\n");
}
end_table();
print("<p>$pagemenu<br />$browsemenu</p>");
end_frame();
stdfoot();
?>
No users online
Torrents
Members
Online