pamma83
11-24-06, 04:40 AM
Hello
I have this code which tells a persons ranking among other users in the database according to rating. However the current ranking is shown in a list. I wanted to know if the coding can be modified to be shown in a persons profile page rather than a list.
the code is as follows:
$top_sql = "select * from $tb_user_types order by";
$top_sql .= $ml_order_types_by_rand ? " rand()" : " order_by";
$top_query = mysql_query($top_sql) or die(mysql_error());
while($top_array = mysql_fetch_array($top_query)){
$user_type_id = $top_array["id"];
$user_type = $top_array["user_type"];
$cml_sql = "select count(*) as count from $tb_users where user_type = '$user_type_id' and image_status = 'approved'";
$cml_query = mysql_query($cml_sql) or die(mysql_error());
if(mysql_result($cml_query, 0, "count") > 0){
$list_sql = "select * from $tb_users where user_type = '$user_type_id' and image_status = 'approved'";
if($ml_use_min_rating){
$list_sql .= " and average_rating >= '$ml_min_rating'";
}
$list_sql .= " order by average_rating desc";
if($ml_use_max_count){
$list_sql .= " limit $ml_count";
}
$list_query = mysql_query($list_sql) or die(mysql_query());
$total=mysql_num_rows($list_query);
//echo $total;
//exit();
if(mysql_num_rows($list_query)>0)
{
$i = 0;
while($list_array = mysql_fetch_array($list_query))
{
$alt = $i % 2 ? "alt1" : "alt2";
$i++;
$name = substr($list_array["username"], 0, $max_un_length);
$name = ucwords(strtolower($name));
$rank=$i . "/" . $total;
$tpl->assign(array('BOX_TOP_NAME' => $name,
'BOX_TOP_URL' => "$base_url/?i=$list_array[id]",
'BOX_TOP_RANK' => "$rank",
'BOX_TOP_IMAGE' => "$base_url/images/$list_array[id]" . "_1." . "$list_array[image_ext]",
'BOX_TOP_BASE_URL' => "$base_url/include/preview_templates.js",
'BOX_TOP_RATE' => $list_array['average_rating']));
$tpl->parse('ROWS_BOXTOP', ($i == 1 ? 'row_boxtop' : '.row_boxtop'));
}
$tpl->assign(array('BOX_TOP_TYPE' => $user_type,
'BOX_TOP_LINK_MORE' => "$base_url/toplist.php?ut=$user_type_id",
'BOX_TOP_TITLE' => $user_type));
$tpl->parse('BOXES_TOP', '.boxtop');
} else
{
// empty
}
}
}
I wanted to try and make the code above to get the data from the database and then rank the members according to that instead of a list which is already being ordered from top rating on top.
I have this code which tells a persons ranking among other users in the database according to rating. However the current ranking is shown in a list. I wanted to know if the coding can be modified to be shown in a persons profile page rather than a list.
the code is as follows:
$top_sql = "select * from $tb_user_types order by";
$top_sql .= $ml_order_types_by_rand ? " rand()" : " order_by";
$top_query = mysql_query($top_sql) or die(mysql_error());
while($top_array = mysql_fetch_array($top_query)){
$user_type_id = $top_array["id"];
$user_type = $top_array["user_type"];
$cml_sql = "select count(*) as count from $tb_users where user_type = '$user_type_id' and image_status = 'approved'";
$cml_query = mysql_query($cml_sql) or die(mysql_error());
if(mysql_result($cml_query, 0, "count") > 0){
$list_sql = "select * from $tb_users where user_type = '$user_type_id' and image_status = 'approved'";
if($ml_use_min_rating){
$list_sql .= " and average_rating >= '$ml_min_rating'";
}
$list_sql .= " order by average_rating desc";
if($ml_use_max_count){
$list_sql .= " limit $ml_count";
}
$list_query = mysql_query($list_sql) or die(mysql_query());
$total=mysql_num_rows($list_query);
//echo $total;
//exit();
if(mysql_num_rows($list_query)>0)
{
$i = 0;
while($list_array = mysql_fetch_array($list_query))
{
$alt = $i % 2 ? "alt1" : "alt2";
$i++;
$name = substr($list_array["username"], 0, $max_un_length);
$name = ucwords(strtolower($name));
$rank=$i . "/" . $total;
$tpl->assign(array('BOX_TOP_NAME' => $name,
'BOX_TOP_URL' => "$base_url/?i=$list_array[id]",
'BOX_TOP_RANK' => "$rank",
'BOX_TOP_IMAGE' => "$base_url/images/$list_array[id]" . "_1." . "$list_array[image_ext]",
'BOX_TOP_BASE_URL' => "$base_url/include/preview_templates.js",
'BOX_TOP_RATE' => $list_array['average_rating']));
$tpl->parse('ROWS_BOXTOP', ($i == 1 ? 'row_boxtop' : '.row_boxtop'));
}
$tpl->assign(array('BOX_TOP_TYPE' => $user_type,
'BOX_TOP_LINK_MORE' => "$base_url/toplist.php?ut=$user_type_id",
'BOX_TOP_TITLE' => $user_type));
$tpl->parse('BOXES_TOP', '.boxtop');
} else
{
// empty
}
}
}
I wanted to try and make the code above to get the data from the database and then rank the members according to that instead of a list which is already being ordered from top rating on top.