rating on any page code in magento

<div class="right-info">
                                 <?php
                                $rating = array();
                                   $product_id = Mage::registry('product')->getId();
                                $resource = Mage::getSingleton('core/resource');
                                $cn= $resource->getConnection('core_read');
                                $sql = "select rt.rating_code,
                                        avg(vote.percent) as percent from ".$resource->getTableName('rating_option_vote')." as vote
                                        inner join ".$resource->getTableName('rating')." as rt
                                        on(vote.rating_id=rt.rating_id)
                                        inner join ".$resource->getTableName('review')." as rr
                                        on(vote.entity_pk_value=rr.entity_pk_value)
                                        where rt.entity_id=1 and vote.entity_pk_value=$product_id and rr.status_id=1
                                        group by rt.rating_code";
                                $rating = $cn->fetchAll($sql);
                                $rating;
                                foreach($rating as $rating) { ?>
                                <div class="info-slide">
                                    <span><?php echo $rating['rating_code']; ?></span>
                                     <div class="design-box">
                                     <div class="process-bar">
                                <span style="width:<?php echo round($rating['percent']).'%'; ?>"></span>
                                </div>
                                <div class="box-bg"></div>
                                </div>
                                </div><?php } ?>                                
                                </div>

Comments