Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am a yiibie. I have top 5 ngo's on my view page(top 5 ngo's for each month) and also the top 5 ngo's at the end of the year on the same page. Now i want to show the bootstrap progress bar in front of every ngo. For example if January is the month and it is showing me top 5 ngo's of that month,I want to show a progress bar in front of all those 5 ngo's and I want it for every month. And same thing for the end of the year. Like the 1st ngo progress bar will be 100%, 2nd ngo will have less then 100% and so on. Please help me in doing this, thank you. This is my code for my controller which has the view file function

           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));
}

and this is my view file(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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
135 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is for the month i hope you are able to adapt for the year

Is simple at begin the var $val is set to 100 and this value is assigned where it is needed then is decremented by 20 and the cycle is repeated

 <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> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...