我想从最高到最低 cip 以及从最低到最高 cip 排序,但是 cip 值不存储在数据库中,它会在查询被触发时立即计算。这是选择排序的html代码:
<select name="cip">
<option>Select CIP percentage</option>
<option value="1">Highest To Lowest</option>
<option value="2">Lowest To Highest</option>
</select>
这是我发出的查询!
$select_applicant = "SELECT j.*, u.id, u.gender
FROM job_apply j
LEFT JOIN users u
ON u.id = j.user_id
WHERE j.job_id = '".$jid."'";
$result_applicant = mysqli_query($con, $select_applicant);
while($row_applicant = mysqli_fetch_assoc($result_applicant))
{
$user_id = $row_applicant["user_id"];
$user_info = get_user_profile_info($user_id);
$ratings_dist = get_skill_ratings_stats($user_id);
$got_it_total_rating = 0;
foreach($ratings_dist as $category=>$rating)
{
$got_it_total_rating = $got_it_total_rating + $rating['score'];
}
$got_it_total_category = count($ratings_dist);
$total_cip = ceil($got_it_total_rating / $got_it_total_category);
echo $total_cip;
}
php中的“get_skill_ratings_stats”函数如下:
function get_skill_ratings_stats($user_id){
global $con;
$items = array();
if($user_id>0)
{
$sql = "SELECT
s.category_id category_id,
c.name as category,
COALESCE(r.score_quality, 0.0) quality,
COALESCE(r.score_timing, 0.0) timing,
COALESCE(r.score_budget, 0.0) budget,
COALESCE(r.score_resp, 0.0) resp,
COALESCE(r.score_pro, 0.0) pro
FROM `user_skills` s
LEFT JOIN `skill_categories` c
ON c.category_id=s.category_id
LEFT JOIN `skill_ratings` r
ON r.skill_id=s.skill_id
WHERE s.user_id = '".(int)$user_id."'
AND s.status = 'active'
ORDER BY category ASC";
$prev_cat = '';
$result = mysqli_query($con, $sql);
// die(mysqli_error($con));
while($row = mysqli_fetch_assoc($result))
{
// print_r($row);
if(!$row['category']) continue;
if($row['category']!=$prev_cat)
{
if(isset($items[$prev_cat]['score']) && $items[$prev_cat]['score']>0 && count($items[$prev_cat])>1)
{
$items[$prev_cat]['score'] = floor(($items[$prev_cat]['score']*20)/(count($items[$prev_cat])-1));
}
$prev_cat = $row['category'];
}
if(!isset($items[$prev_cat]['score'])) $items[$prev_cat]['score'] = 0;
$items[$prev_cat][] = $row;
$items[$prev_cat]['score'] += ($row['quality']+$row['timing']+$row['budget']+$row['resp']+$row['pro'])/5;
}
}
// print_r($items);
// die();
if(isset($items[$prev_cat]['score']) && $items[$prev_cat]['score']>0 && count($items[$prev_cat])>1)
{
$items[$prev_cat]['score'] = floor(($items[$prev_cat]['score']*20)/(count($items[$prev_cat])-1));
}
$tmp = array();
foreach($items as $cat=>$item) {
$tmp[$item['score'].'-'.$cat] = $item;
}
krsort($tmp);
$items = array();
foreach($tmp as $k=>$v) {
$k = preg_replace('#^\d+-#is', '', $k);
$items[$k] = $v;
}
// print_r($tmp);
// print_r($items);
// die();
return $items;
}
请帮我!很难受这个!