我是一个yiibie。我在我的视图页面上排名前5位(每个月前5位),并且在同一页面上排在今年年底的前5位。现在我想在每个非政府组织前面显示引导进度条。例如,如果1月份是月份,并且它显示我当月的前5名,那么我想在所有这5个人面前显示一个进度条,我希望每个月都有。同样的事情在今年年底。就像第一个非常进步条将是100%,第二个非比例将少于100%,依此类推。请帮我这样做,谢谢。 这是我的控制器的代码,它具有视图文件功能
public function actionNgostats()
{
$this->layout='main';
$myCurrYear = date("Y");
$userYear=UserRateReviewNgo::model()->findAll(array(
'condition' => 'YEAR(date_created)=:year',
'params' => array(':year'=>$myCurrYear),
'select'=>'DISTINCT rate,ngo_id',
'order'=>'rate DESC',
'limit' => 5
));
$this->render('ngostats', array("userYear"=>$userYear));
}
这是我的视图文件(ngostats)
<div>
<?php
for($month = 1 ; $month <=date('m') ; $month++)
{
$user=UserRateReviewNgo::model()->findAll(array(
'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
'params' => array(':year'=>2015, ':month'=>$month),
'select'=>'DISTINCT rate,ngo_id',
'order'=>'rate DESC',
'limit' => 5
));
foreach($user as $show) {
$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
if (isset($model)) {
?>
<div><h4><?php echo $model->ngo_name?></h4></div>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
40%
</div>
</div>
<?php
}}}
?>
</div>
<h3>This is for the year's top 5 Ngo's</h3>
<div>
<?php // the for the year
foreach($userYear as $show) {
$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
if (isset($model)) {
?>
<div><h4><?php echo $model->ngo_name?></h4></div>
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"
aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
40% Complete (success)
</div>
</div>
<?php
}
}
?>
</div>
答案 0 :(得分:1)
本月我希望你能适应这一年
在开始时很简单,var $ val设置为100,并且在需要的地方分配此值,然后递减20并重复循环
<div>
<?php
for($month = 1 ; $month <=date('m') ; $month++)
{
$dateObj = DateTime::createFromFormat('!m', $month);
$monthName = $dateObj->format('F');
echo "<h3> " . $monthName . "</h3>";
$user=UserRateReviewNgo::model()->findAll(array(
'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
'params' => array(':year'=>2015, ':month'=>$month),
'select'=>'DISTINCT rate,ngo_id',
'order'=>'rate DESC',
'limit' => 5
));
$val = 100;
foreach($user as $show) {
$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
if (isset($model)) {
echo "<div><h4>" . $model->ngo_name ."</h4></div>
<div class='progress'>
<div class='progress-bar progress-bar-striped active' role='progressbar'
aria-valuenow='" . $val ."' aria-valuemin='0' aria-valuemax='100' style='width: ". $val ."%;'>" . $val .
"</div>
</div>";
$val = $val -20;
}}}
?>
</div>